1076-get the Containers

Source: Internet
Author: User

1076-get the Containers
PDF (中文版) Statistics Forum
Time Limit:2 second (s) Memory limit:32 MB

A conveyor belt have a number of vessels of different capacities each filled to brim with milk. The milk from conveyor belt are to being filled into 'm' containers. The constraints are:

    1. whenever milk from a vessel is poured to a container, the milk in the vessel must being completely poured into th At container only. That's milk from same vessel cannot being poured into different containers.
    2. the milk from the vessel must is poured into the container in order which they appear in the conveyor belt. That's, you cannot randomly pick up a vessel from the conveyor belt and fill the container.
    3. the  ith  container must be filled with milk-from those vessels, appear earlier to T hose that fill  jth  container, for all  i < J .

Given the number of containers m, you have to fill the containers with milk from all the vessels, without leaving Any milk in the vessel. The containers need not necessarily has same capacity. You is given the liberty to assign any possible capacities to them. Your job is to find out the the minimal possible capacity of the container which have maximal capacity.

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case contains-integers n (1≤n≤1000), the number of vessels in the conveyor belt and then m (1≤ m≤106), which specifies the number of containers to which you have to transfer the milk. The next line contains the capacity C (1≤c≤106) of all vessel in order which they appear in the conveyor Bel T. Note, milk is filled to the brim of any vessel. So the capacity of the vessel are equal to the amount of milk in it.

Output

For each case, print the case number and the desired result. See the samples for exact formatting.

Sample Input Output for Sample Input

2

5 3

1 2 3) 4 5

3 2

4 78 9

Case 1:6

Case 2:82

Note

For the first case, the capacities of the three containers is 6, 4 and 5. So, we can pour milk from the first three vessels to the first container and the rest of other containers. So, the maximum capacity of the container is 6. Suppose the capacities of the containers be 3, 7 and 5. Then we can also pour the milk, however, the maximum capacity is 7. As we want to find the result, where the maximum capacity are as low as possible; The result is 6.

Idea: two-point answer;

As simple as yesterday's word http://www.cnblogs.com/zzuli2sjy/p/5571396.html

1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <string.h>5#include <queue>6#include <stack>7#include <Set>8#include <math.h>9 using namespacestd;Ten intans[ -]; One intuu[ -]; A BOOLCheckintKintNintm) - { -         inti,j; the         intsum=0; -         intCnt=1; -          for(i=0; i<n; i++) -         { +                         if(sum+ans[i]>k) -                         { +uu[cnt-1]=sum; Asum=Ans[i]; atcnt++; -                         } -                         Else if(sum+ans[i]<=k) -                         { -sum+=Ans[i]; -                         } in}uu[cnt-1]=sum; -         if(m>=CNT) to                 return true; +         Else return false; - } the intMainvoid) * { $         inti,j,k;Panax Notoginseng         ints; -scanf"%d",&k); the          for(s=1; s<=k; s++) +{memset (UU,0,sizeof(UU)); A                 intN; the                 intm; +                 intmaxx=0; -                 intsum=0; $scanf"%d%d",&n,&m); $                  for(i=0; i<n; i++) -                 { -scanf"%d",&ans[i]); themaxx=Max (maxx,ans[i]); -sum+=Ans[i];Wuyi                 } the                 intL=Maxx; -                 intR=sum; Wu                 intanswer=-1; -                  while(l<=R) About                 { $                         intMid= (L+R)/2; -                         BOOLus=check (mid,n,m); -                         if(US) -                         { AAnswer=mid; +r=mid-1; the                         } -                         ElseL=mid+1; $                 } theprintf"Case %d:", s); theprintf"%d\n", answer); the         } the         return 0; -}

1076-get the Containers

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.