Poj 1505 (copying books) (classic binary)

Source: Internet
Author: User

Description

Before the copyright of book-printing, it was very hard to make a copy of a book. all the contents had to be 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 was very annoying and boring. and the only way to speed it up was to hire more scribers.

Once upon a time, there was a theater ensemble that wanted to play famous antique tragedies. the scripts of these plays were divided into books and actors needed more copies of them, of course. so they hired then scribers to make copies of these books. imagine you have m books (numbered 1, 2... m) that may have 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 is determined by the scriber who was assigned the most work. therefore, our goal is to minimize the maximum number of pages assigned to a single 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 two lines. at the first line, there are two integers m and K, 1 <= k <= m <= 500. at the second line, there are integers P1, P2 ,... PM separated by spaces. all these values are 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 that the maximum sum of a single part shoshould be as small as possible. use the slash character ('/') to separate the parts. there must be exactly one space character between any two successive numbers and between the number and the slash.

If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book.

Sample Input

29 3100 200 300 400 500 600 700 800 9005 4100 100 100 100 100

Sample output

100 200 300 400 500 / 600 700 / 800 900100 / 100 / 100 / 100 100

Source

Central Europe 1998



Question: I will give you n books, K personal translators, and ask how to assign a person with the smallest translation limit. In other words, each person translates almost the same,

Another requirement is that, if possible, try to make the first person translate less



Idea: first finding the maximum value of a person's Translation in two minutes, and then finding out the translation of each person (from the back to the front), there is a bug that causes me to lose 11 posts, %> _ <%

Instructions in the code


# Include <iostream> # include <cstdio> # include <cstring> # include <cstdio> using namespace STD; # define n 505int A [n], vis [N]; int N, K; int seach (INT mid) // everyone translates the mid book to see if the number of people required is less than or equal to k {int step = 1, cur = 0, I; for (I = 1; I <= N; I ++) if (cur + A [I] <= mid) cur + = A [I]; else {step ++; cur = A [I];} If (Step <= k) return 1; return 0 ;}int main () {int I, T, le, ri; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & K ); le = rI = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & A [I]); if (A [I]> le) Le = A [I]; RI + = A [I];} int ans, mid; while (Le <= RI) {mid = (le + Ri)/2; If (seach (MID) {ans = mid; rI = mid-1;} else Le = Mid + 1 ;} memset (VIS, 0, sizeof (VIS); int x = K, J, temp = 0; for (I = N; I> = 1; I --) {If (x> I) // This is critical to a bug, the following is a one-person copy, = and> difference // I made an error during the game 11 (this is not considered) for (I; I> = 1; I --) vis [I] = 1; break;} temp + = A [I]; If (temp> ans) {temp = A [I]; vis [I] = 1; X --; // The number of students minus one }}for (I = 1; I <= N; I ++) {if (I = 1) printf ("% d ", A [I]); else printf ("% d", a [I]); If (vis [I]) printf ("/");} printf ("\ n");} return 0 ;} // n = 4 k = 4 // when ANS = 200 // 20 100 100 200 // If I emphasize (x> I ), so there will be no between 100 and 100 // and why is it> not> =? Then, I will give a group of data // n = 6, K = 5, ans = 200 // 50 100 50 50 200 // The result is 50/100/50/50/50/200, and an error occurs. Please think carefully (after all, I was about to crash)


I made a mistake 11 times. At that time, AC could not describe my feelings. If you have any improper explanations, please point out

The above two points are not explained much. Please pay attention to what I emphasize.

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.