3399: [Usaco2009 Mar]sand Castle Castle time Limit:3 Sec Memory limit:128 MB
submit:79 solved:66
[Submit] [Status] [Discuss] Description John built a castle with sand. Like the walls of all the castles, the walls also have many loophole, and the middle part of the two adjacent loophole is called the "City Teeth". There is a total of N (1≤n≤25000) on the city wall, each with a height of mi. (1≤ embarrassed ≤100000). Now John wants to tune the height of the city teeth into a bi,b2,...,bn (i≤bi≤100000) in some order. -Each one of the city teeth increases the height of a unit, John needs X (i≤x≤100) yuan; For each lowering of the height of a unit, John needs Y (1≤y≤100) dollars. Ask John how much money he can use at least to achieve his goal. The data guarantees that the answer is no more than 2^32. Input line 1th enters 3 integer n,x,y. Enter two whole numbers of MI and bi for each line from 2nd to n+1 lines. Minimum Output cost. Sample INPUT3 6 5
3 1
0 S
1 2Sample Output11hint
1th City teeth reduced by 1, 2nd city teeth increased by 1
Source
Silver
There is a very intuitive conclusion that the smaller the certainty corresponds to the smaller, the greater the certainty corresponds to the greater. Then sort of messing around.
/************************************************************** problem:3399 user:ecnu161616 language:c++ result:accepted time:24 ms memory:2856 kb********************************************** /#include <bits/stdc++.h>using namespace std; int n, x, Y;int a[200000], b[200000];long long ans; int main () { #ifdef ultmaster freopen ("a.in", "R", stdin); #endif scanf ("%d%d%d", &n, &x, &y); for (int i = 0; i < n; ++i) scanf ("%d%d", &a[i], &b[i]); Sort (A, a + N); Sort (b, B + N); for (int i = 0; i < n; ++i) { if (A[i] < b[i]) ans + = 1LL * (B[i]-a[i]) * x; else ans + = 1LL * (A[i]-b[i]) * y; } printf ("%lld\n", ans); return 0;}
[BZOJ3399] [Usaco2009 Mar] Sand Castle Castle (sort)