Poj1505:copying Books Problem Solving experience

Source: Internet
Author: User

Original question:

Description

Before the invention of book-printing, it is very hard-make a copy of a book. All of the contents had to is re-written by hand and 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 its 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 havemBooks (numbered) the May has different number of pages () and want to make one copy of each of the them. Your task is to divide these books amongkScribes,. Each book can is assigned to a scriber only, and every scriber must get a continuous sequence of books. That is means, there exists an increasing succession of numbers such thatI-th Scriber gets a sequence of books with numbers betweenbI-1+1 andbI. The time needed to make a copy of the "All the books are determined by the" the Scriber who were assigned the most work. Therefore, our goal are 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-lines. At the first line, there is integers m and K,. At the second line, there is integers 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 divided to exactly Kparts such that the maximum sum of a single par T should be as small as possible. Use the slash character ('/') to separate the parts. There must is exactly one space character between any of the 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 and then the Secon D Scriber etc. But each scriber must is 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

Test instructions: To some books, these books have a different number of pages, so that the books are divided into K parts, must be continuous, ask the number of pages and the maximum value of the minimum.

Train of thought: first can use two to cite the maximum minimum value, and then output the time from the forward to determine the output, this maximum minimization of the problem in the book so

Introduction to:

Code:

#include <iostream>#include<cstdio>using namespacestd;inta[505];intMain () {intT; CIN>>T;  while(t--){        intm, K; Long Longmid; Long LongTotal=0; CIN>> m >>K;  for(inti =0; I < m; i++) {scanf ("%d", &A[i]); Total+=A[i]; } cout<< Total <<Endl; Long Longleft =0, right =Total ;  while(left<Right ) {Mid= (left + right)/2; if(K*mid >=Total ) right=mid; Else Left= mid+1; } cout<< left<<' '<<right <<Endl; }    return 0;}

Poj1505:copying Books Problem Solving experience

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.