Greedy... How could I not qaq "face-covering bear"?
For 1, 22 cows, if 1th cattle are to be lined up in front of the number 2nd to be less time, then
$ $max (a_1 + b_1 + b_2, \ a_1 + a_2 + b_2) \le max (a_2 + b_2 + b_1, \ a_2 + a_1 + b_1) \ \leftrightarrow min (a_1, \ b_2) & Lt Min (a_2, \ b_1) $$
So it would be nice to simulate it after the sort.
1 /**************************************************************2 problem:17273 User:rausen4 language:c++5 result:accepted6 time:48 Ms7 memory:1156 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A using namespacestd; - Const intN = 3e4 +5; - Const intINF =1e9; the -Inlineintread (); - - structData { + intA, B, K; - +Inlinevoid Get() { AA = read (), B =read (); at if(A < b) k =A; - ElseK = inf-b; - } - -InlineBOOL operator< (ConstData &d)Const { - returnK <D.K; in } - } A[n]; to + intN, ans; - the intMain () { * inti, T1, T2; $n =read ();Panax Notoginseng for(i =1; I <= N; ++i) A[i].Get(); -Sort (A +1, A + n +1); the for(i =1, t2 =0; I <= N; ++i) T2 + =a[i].b; + for(i =1, T1 = ans =0; I <= N; ++i) { AT1 + =a[i].a; theans = max (ans, T1 +T2); +T2-=a[i].b; - } $printf"%d\n", ans); $ return 0; - } - theInlineintRead () { - Static intx;Wuyi Static Charch; thex =0, ch =GetChar (); - while(Ch <'0'||'9'<ch) WuCH =GetChar (); - while('0'<= CH && Ch <='9') { Aboutx = x *Ten+ CH-'0'; $CH =GetChar (); - } - returnx; -}View Code
BZOJ1727 [Usaco2006 open]the Milk Queue milking queues