Before the invention of book-printing, it is very hard-make a copy of a book. All the contents had
To is re-written by hand by so called Scribers. The scriber had been given a book and after several
Months he finished its copy. One of the most famous Scribers lived in the 15th century and his name
Was Xaverius endricus Remius Ontius xendrianus (Xerox). Anyway, the work is very annoying and
Boring. And the only-to-speed it up is to hire more scribers.
Once upon a time, there was a theater ensemble the wanted to play famous antique tragedies. The
Scripts of these plays were divided into many books and actors needed more copies of them, of course.
So they hired many scribers to make copies of these books. Imagine you have m books (numbered
1; 2; :::; m) that is different number of pages (P1; p2;:::; pm) and you want to make one copy of
Each of them. Your task is to divide these books among K scribes, K M. Each book can be assigned
To a single scriber only, and every scriber must get a continuous sequence of books. That means, there
exists an increasing succession of numbers 0 = B0 < B1 < B2; ::: < BK?? 1 BK = m such that i-th Scriber
Gets a sequence of books with numbers between bi?? 1 + 1 and bi. The time needed to make a copy of
All the books are determined by the Scriber and who are assigned the most work. Therefore, our goal are to
Minimize the maximum number of pages assigned to a and scriber. Your task is to find the optimal
Assignment.
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow
The cases. Each case consists of exactly-lines. At the first line, there is integers m and K,
1 K M 500. At the second line, there is integers p1; P2; : : : ; PM separated by spaces. All these
Values is positive and less than 10000000.
Output
For each case, print exactly one line. The line must contain the input succession P1; P2; ::: PM divided
into exactly k parts such, the maximum sum of a single part should be as small as possible. Use
The slash character ('/') to separate the parts. There must is exactly one space character between any
Successive numbers and between the number and the slash.
If there is more than one solution, print the one of the minimizes the work assigned to the first Scriber,
Then to the second scriber etc. But each scriber must is assigned at least one book.
1#include <cstdio>2#include <cstring>3 #defineM (a) memset (A,0,sizeof (a))4 Long Longa[510],b[510];5 intMain ()6 {7 Long LongI,j,k,m,n,p,q,x,y,z,t,l,r;8scanf"%lld",&t);9 while(t--)Ten { One M (a); A M (b); -scanf"%lld%lld",&n,&p); - for(i=1; i<=n;i++) thescanf"%lld",&a[i]); -x=0; -y=a[1]; - for(i=1; i<=n;i++) + { -x+=A[i]; + if(a[i]>y) y=A[i]; A } atL=y; -R=x; - while(l<R) - { -M= (L+R)/2; -x=a[1]; iny=1; - for(i=2; i<=n;i++) to if(x+a[i]<=m) +x+=A[i]; - Else the { *y++; $x=A[i];Panax Notoginseng } - if(y<=p) r=m; the Elsel=m+1; + } Aj=N; the for(i=p-1; i>=1; i--) + { -x=0; $ while(j>i&&x+a[j]<=l) $x+=a[j--]; -b[i]=J; - } theb[0]=0; - for(i=1; i<=p-1; i++)Wuyi { the for(j=b[i-1]+1; j<=b[i];j++) -printf"%lld", A[j]); Wuprintf"/ "); - } Aboutprintf"%lld", a[b[p-1]+1]); $ for(i=b[p-1]+2; i<=n;i++) -printf"%lld", A[i]); -printf"\ n"); - } A}
This question is simply a copy of last year's NOIP jumping stone!!! "The latter is, of course, a replica of the former."
Two-point answer, judge the time from left to right as far as possible to draw until can not.
The output of the time to start from the back greedy.
"Noip Raise group 2015D2T1" UVA 714 copying Books "Two-point answer"--YHX