We first sort all the batteries, then we can find a set of optimal schemes, so that the difference in energy of one machine is the difference of energy between two adjacent cells.
Then we have two points of the answer, the former greedy to choose the number of pairs, and then see whether all the pairs are satisfied with the conditions.
Assuming that the number pair is i-1, I, and is the number of J pairs, then we call the satisfying condition:
2nk-i + 2 >= 2k (n-j + 1)
It means that you can get enough batteries to make a robot.
Then pay attention to the special sentence: If you cannot select enough number pairs to return false, I am here WA to die ...
After all, Gromah is too weak to do water problems.
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 #defineN 1000000 + 58 9 intN, k, size, Max, a[n];Ten OneInlineintGetint () A { - CharCH ='\ n'; - for(; CH >'9'|| Ch <'0'; CH =GetChar ()); the intres = CH-'0'; - for(ch = getchar (); Ch >='0'&& CH <='9'; CH =GetChar ()) -res = (Res <<3) + (res <<1) + CH-'0'; - returnRes; + } - +InlineBOOLJudge (intm) A { at intCNT =N; - for(inti =2; CNT && i <= size; i + +) - if(A[i]-a[i-1] <=m) - { - if(Size-i +2<2* CNT * k)return 0; -CNT--, i + +; in } - return!CNT; to } + - intMain () the { * #ifndef Online_judge $Freopen ("3969.in","R", stdin);Panax NotoginsengFreopen ("3969.out","W", stdout); - #endif the +n = Getint (), k =getint (); ASize = (n * k) <<1; the for(inti =1; I <= size; i + +) + { -A[i] =getint (); $Max =Max (max, a[i]); $ } -Sort (A +1, A + size +1); - intL = a[2]-a[1], R =Max; the while(L <R) - {Wuyi intMid = (L + r) >>1; the if(Judge (mid)) R =mid; - ElseL = mid +1; Wu } -printf"%d\n", L); About $ #ifndef Online_judge - fclose (stdin); - fclose (stdout); - #endif A return 0; +}
Bzoj 3969 Low Power Problem Solving report