ZOJ
来源:互联网 发布:facebook网络错误 编辑:程序博客网 时间:2024/05/16 19:28
As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going to cook all dishes himself, in order to show off his genius cooking skill to his girlfriend.
To make full use of his genius in cooking, Coach Gao decides to prepare N dishes for the dinner. The i-th dish contains Ai steps. The steps of a dish should be finished sequentially. In each minute of the cooking, Coach Gao can choose at most M different dishes and finish one step for each dish chosen.
Coach Gao wants to know the least time he needs to prepare the dinner.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains two integers N and M (1 <= N, M <= 40000). The second line contains N integers Ai (1 <= Ai <= 40000).
Output
For each test case, output the least time (in minute) to finish all dishes.
Sample Input
23 22 2 210 61 2 3 4 5 6 7 8 9 10
Sample Output
310
Author: JIANG, Kai
Source: The 11th Zhejiang Provincial Collegiate Programming Cont
厨师总会尽可能每分钟做m个菜,于是取决于步骤最多的菜和理想情况
#include<iostream>#include<cstdio>#include<math.h>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<list>#include<vector>#include<sstream>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define ms(x,y)memset(x,y,sizeof(x))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define ll long longconst int INF=0x7ffffff;const int M=2e4+10;int i,j,k,n,m;int pa[M];int main(){ int T; scanf("%d",&T); while(T--){ ll sum=0; scanf("%d%d",&n,&m); int mm=0; for(i=0;i<n;i++){ int a; scanf("%d",&a); sum+=a; mm=max(mm,a); } ll ans=sum/m; if(sum%m!=0)ans+=1; printf("%lld\n",mm>ans?mm:ans); } return 0;}
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- Must Know Tips/tricks in DNN
- iOS学习笔记 ——文件操作(NSFileManager)
- Android Studio如何正确打jar包
- 数据库连接池
- ios 苹果内购踩过的坑
- ZOJ
- HTML简介以及基本使用
- sql优化:避免全表扫描
- if 中的true 和false值
- Java读写配置文件properties
- Android中的Looper , Handler , Message的关系,异步消息处理的机制,根据源码分析
- 关闭“**程序已停止”提示窗口
- NJCTF 2017 web pictures'wall(详解)
- Tomcat服务器之于javaweb