The problem of minimizing this maximum value is determined by the first two points.
Assuming that the maximum value of each interval is x, then just be greedy when judging.
That is, if and not more than X will be in the interval to the number of places, or open a new interval, so as to determine whether the K-interval can be the number of these.
There is the output is also very troublesome, borrowed a bit of LRJ code, feeling is very ingenious.
1#include <bits/stdc++.h>2 using namespacestd;3 4typedefLong LongLL;5 Const intMAXN = -+Ten;6 LL A[MAXN];7 BOOLLAST[MAXN];8 intN, K;9 Ten BOOLCheck (LL x) One { A intCNT =1; - for(inti =0, J; I < n; i =j) - { the if(CNT > K)return false; -LL s =0; - for(j = i; J < N; j + +) - { + if(A[j] > x)return false; - if(S + a[j] <= x) s + =A[j]; + Else Break; A } atcnt++; - } - return true; - } - - intMain () in { - //freopen ("In.txt", "R", stdin); to //freopen ("OUT.txt", "w", stdout); + - intT scanf"%d", &T); the while(t--) * { $scanf"%d%d", &n, &k);Panax NotoginsengLL L =0, R =0; - for(inti =0; I < n; i++) {scanf ("%lld", &a[i]); R + =a[i];} the while(L <R) + { ALL mid = (L + R)/2; the if(Check (mid)) R =mid; + ElseL = mid +1; - } $ $Memset (Last,false,sizeof(last)); -LL s =0;intR =K; - for(inti = n1; I >=0; i--) the { - if(S + a[i] > L | | i +1<R)Wuyi { theLast[i] =true; -s =A[i]; Wur--; - } About Elses + =A[i]; $ } - for(inti =0; I < n1; i++) - { -printf"%lld", A[i]); A if(Last[i]) printf ("/ "); + } theprintf"%lld\n", a[n-1]); - } $ the return 0; the}code June
UVa 714 (bis) Copying Books