UVa 714 (bis) Copying Books

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.