济南学习 Day 1 T2 am

死亡
【问题描述】
现在有M个位置可以打 sif,有N +1个人在排队等着打 sif。现在告诉你 个人每个人需要多长的时间打 sif,问你第N +1个人什么时候才能打 sif。 (前N
个人必须按照顺序来)
【输入格式】
第一行两个整数N,M如上所述。
接下来N行每行一个整数代表每个人所需要用的时间。
【输出格式】
一行一个整数表示答案。
【样例输入】
3 2
1
1
1
【样例输出】
1
【样例解释】
山里有座庙。
【数据规模与约定】
对于100%的数据,每个人所需用的时间不超过10 5 。

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <queue>
 9 using namespace std;
10 priority_queue<int, vector<int>, greater<int> > a;
11 int main()
12 {
13     freopen("death.in","r",stdin);
14     freopen("death.out","w",stdout);
15     int n,i,t,ok=0,x=0,k;
16     scanf("%d%d",&n,&k);
17     for(int i=1;i<=k;i++)
18       a.push(0);
19     for(i=0; i<n; i++)    
20     {
21         scanf("%d",&t);
22         int now=a.top();
23         a.pop();
24         now+=t;
25         a.push(now);
26     }
27     /*int maxx=0;
28     while(!a.empty())
29     {
30         maxx=a.top();
31         a.pop();
32     }    */
33     cout<<a.top()<<endl;
34     fclose(stdin);
35     fclose(stdout);
36     return 0;
37 }

另附测试数据:

输入:
10 10
42
18468
6335
26501
19170
15725
11479
29359
26963
24465
输出:
42
测试点一

其余的见网盘

思路:优先队列,打到最后的时候,堆顶的那个人的打完时间即为第N+1个人开始打sif的时间

posted @ 2016-11-04 09:19  浮华的终成空  阅读(168)  评论(0编辑  收藏  举报

Contact with me