3399: [Usaco2009 Mar]sand Castle Castle time Limit:3 Sec Memory limit:128 MB
Submit:37 solved:32
[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
1 2
1 2Sample Output11hint
1th City teeth reduced by 1, 2nd city teeth increased by 1
Source
Silver
Problem: is a stone (sang) Broken (xin) days (Bing) surprised (Kuang) of greed, the original is a sequence of the order is good = = (Hansbug: More and more found this kind of greedy problem is the most tease than there is a wood TT)
1/**************************************************************2Problem:33993 User:hansbug4 language:pascal5 result:accepted6Time: +Ms7Memory:1008KB8****************************************************************/9 Ten type OneArr=Array[0..100000] ofLongint; A var - I,j,k,l,m,n:longint; - A,b:arr;ans:int64; the procedureSwapvarx,y:longint); - varZ:longint; - begin -z:=x;x:=y;y:=Z; + End; - procedureSort (l,r:longint;varA:arr); + varI,j,x,y:longint; A begin ati:=l;j:=r;x:=a[(L+r)Div 2]; - Repeat - whileA[i]<x DoInc (i); - whileA[j]>x DoDec (j); - ifI<=j Then - begin in swap (a[i],a[j]); - Inc (I);d EC (j); to End; + untilI>J; - ifI<r Thensort (i,r,a); the ifL<j Thensort (l,j,a); * End; $ functioncal (X,y:longint): Int64;Panax Notoginseng begin - ifY>=x ThenExit (Int64 (k) *int64 (y-x))ElseExit (Int64 (L) *int64 (xy)); the End; + begin A readln (n,k,l); the fori:=1 toN Doreadln (A[i],b[i]); +Sort1, n,a); Sort (1, n,b); -ans:=0; $ fori:=1 toN DoInc (Ans,cal (A[i],b[i)); $ writeln (ans); - Readln; - End.
3399: [Usaco2009 Mar]sand Castle Castle