The main topic: there is a person's budget deficit, every day to pay a certain amount of money, altogether to still n days.
Now he asked to turn the N-day money into M-time, that is, do not have to pay every day, you can accumulate a certain number of days to pay off.
Now ask for M-time to drop the money, the maximum value of money to the smallest, ask this minimum is how much
Solving ideas: Minimum maximum, two-point solution
The minimum value of the enumeration is the maximum value of the money that is paid daily, and the maximum is the sum of the money that is paid daily.
Because each time the enumeration of money must be greater than or equal to the maximum value of the money per day, so can be divided into n sets, and then in the smallest collection, the minimum number of collections is each set to contain more days
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define MAXN 100010Long LongNum[maxn],sum, Min;intN, M;BOOLJudgeLong LongMID) {intCNT =1, Count;Long LongMoney =0; for(inti =0; i < N; i++) {money + = Num[i];if(Money > Mid) {Money =0; i--; cnt++; } }if(CNT <= M)return true;return false;}Long LongSolve () {Long LongL = Min, r = Sum; while(L < R) {Long LongMid = (L + r)/2;if(Judge (mid)) R = mid-1;ElseL = mid +1; }returnl;}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {Sum =0, Min =-1; for(inti =0; i < N; i++) {scanf("%lld", &num[i]); min = max (min, num[i]); Sum + = Num[i]; }printf("%lld\n", solve ()); }return 0;}
POJ-3273 Monthly Expense two points