1076 - Get the Containers
Time Limit: 2 second(s) Memory Limit: 32 MB

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

  1. Whenever milk from a vessel is poured into a container, the milk in the vessel must be completely poured into that container only. That is milk from same vessel cannot be poured into different containers.
  2. The milk from the vessel must be poured into the container in order which they appear in the conveyor belt. That is, you cannot randomly pick up a vessel from the conveyor belt and fill the container.
  3. The ith container must be filled with milk only from those vessels that appear earlier to those 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 have same capacity. You are given the liberty to assign any possible capacities to them. Your job is to find out the minimal possible capacity of the container which has maximal capacity.

Input

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

Each case contains two 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 each vessel in order which they appear in the conveyor belt. Note that, milk is filled to the brim of any vessel. So the capacity of the vessel is 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 be 6, 4 and 5. So, we can pour milk from the first three vessels to the first container and the rest in other two 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 is as low as possible; the result is 6.

思路:二分答案;

和昨天那道一样还简单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 namespace std;
10 int ans[2000];
11 int uu[2000];
12 bool check(int k,int n,int m)
13 {
14 int i,j;
15 int sum=0;
16 int cnt=1;
17 for(i=0; i<n; i++)
18 {
19 if(sum+ans[i]>k)
20 {
21 uu[cnt-1]=sum;
22 sum=ans[i];
23 cnt++;
24 }
25 else if(sum+ans[i]<=k)
26 {
27 sum+=ans[i];
28 }
29 }uu[cnt-1]=sum;
30 if(m>=cnt)
31 return true;
32 else return false;
33 }
34 int main(void)
35 {
36 int i,j,k;
37 int s;
38 scanf("%d",&k);
39 for(s=1; s<=k; s++)
40 { memset(uu,0,sizeof(uu));
41 int n;
42 int m;
43 int maxx=0;
44 int sum=0;
45 scanf("%d %d",&n,&m);
46 for(i=0; i<n; i++)
47 {
48 scanf("%d",&ans[i]);
49 maxx=max(maxx,ans[i]);
50 sum+=ans[i];
51 }
52 int l=maxx;
53 int r=sum;
54 int answer=-1;
55 while(l<=r)
56 {
57 int mid=(l+r)/2;
58 bool us=check(mid,n,m);
59 if(us)
60 {
61 answer=mid;
62 r=mid-1;
63 }
64 else l=mid+1;
65 }
66 printf("Case %d:",s);
67 printf(" %d\n",answer);
68 }
69 return 0;
70 }

1076 - Get the Containers的更多相关文章

  1. LightOj 1076 - Get the Containers (折半枚举好题)

    题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1076 题目描述: 给出n个数,要求分成m段,问这m段中最大的总和,最小是多少 ...

  2. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  3. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

  4. Conquering Keokradong && Get the Containers(二分)

    Conquering Keokradong Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  5. IBM Bluemix体验:Containers持久存储

    上一篇介绍了在Bluemix Containers服务中使用docker hub镜像和container的高可用配置.接下来我们尝试如何在容器中使用持久存储. 在Bluemix的Containers服 ...

  6. IBM Bluemix体验:Containers进阶

    上一篇中介绍了Bluemix的Containers服务以及如何使用自定义的docker image创建一个容器实例并对外提供服务.除了自定义镜像之外,Bluemix Containers还可以使用Do ...

  7. IBM Bluemix体验:Containers

    国际版的Bluemix目前有三个region,US South,United Kingdom和Sydney.其中US South是功能最全的,UK其次,Sydney功能最少.Containers服务在 ...

  8. Docker-2:network containers

    docker run -d -P --name web training/webapp python app.py # -name means give the to-be-run container ...

  9. Containers Reserved yarn resourcemanager

    yarn rm的管理页面中显示了集群的概况,其中有一个指标叫Containers Reserved . 预留的容器,为什么会预留,集群的资源使用饱合,新的app请求的资源一般会进入pending状态, ...

随机推荐

  1. java poi导出多sheet页

    /** * @Title: exportExcel * @Description: 导出Excel的方法 * @param workbook * @param sheetNum (sheet的位置,0 ...

  2. oracle(数据备份)

    1 --oracle数据备份(三种方法) 2 --1.逻辑备份与恢复:用Oracle提供的工具,导入/导出(exp,imp),数据 3 --泵导入/导出(impdp,expdp),装入器(SQL*Lo ...

  3. d3动态坐标轴

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Spring AOP通过注解的方式设置切面和切入点

    切面相当于一个功能的某一个类,切入点是这个类的某部分和需要额外执行的其他代码块,这两者是多对多的关系,在代码块处指定执行的条件. Aspect1.java package com.yh.aop.sch ...

  5. 9.Vue.js 监听属性

    本章节,我们将为大家介绍 Vue.js 监听属性 watch,我们可以通过 watch 来响应数据的变化. 以下实例通过使用 watch 实现计数器: <div id = "app&q ...

  6. 【C/C++】学生排队吃饭问题

    问题: 有n个学生,学生们都在排队取餐,第个学生在L国时刻来到队尾,同一时刻来的学生编号小的在前,每个时刻当队列不为空时,排在队头的同学就可以拿到今天的中餐并离开队伍,若第个学生R团时刻不能拿到中餐, ...

  7. 10、Redis三种特殊的数据类型

    一.Geospatail地理位置 1.Geospatail的应用 朋友的位置,附近的人,打车距离 2.相关命令 1.geoadd:增加某个地理位置的坐标(可批量添加). 语法: GEOADD key ...

  8. 可扩展标记语言XML(淅淅沥沥的小雨)

    XML简述 XML用于描述数据,是当前处理结构化文档信息的有力工具.与操作系统编程语言的开发平台无关,可以实现不同系统之间的数据交互. xml文件结构: 1 <?xml version=&quo ...

  9. react-hook简单使用

    一.函数式组件创建 function HelloComponent(props, /* context */) { return <div>Hello {props.name}</d ...

  10. [Java Web 王者归来]读书笔记1

    第一章 Java web 开发概述 1 WEB服务器运行时一直在TCP 80(默认端口)监听, 若使用其他端口在url中需要显示标注端口号(例如:8080) 2 WEB服务器:微软的IIS.Apach ...