您的位置:首页 > 理论基础 > 计算机网络

华中农业大学第五届程序设计大赛网络同步赛-K

2017-04-24 12:26 316 查看

K.Deadline

There are N bugs to be repaired and some engineers whose abilities are roughly equal. And an engineer can repair a bug per day. Each bug has a deadline A[i].

Question: How many engineers can repair all bugs before those deadlines at least? 1<=n<= 1e6. 1<=a[i] <=1e9

Input

Description There are multiply test cases. In each case, the first line is an integer N , indicates the number of bugs. The next line is n integers indicates the deadlines of those bugs.

Output

Description There are one number indicates the answer to the question in a line for each case.

Input

4 1 2 3 4

Output

1

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1000005;
int a, book
, day
;

int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int len = 0;
memset(book, 0, sizeof(book));
memset(day, 0, sizeof(day));
for(int i = 0; i < n; i++)
{
scanf("%d", &a);
if(a <= n)
book[a]++;
if(a < n && a > len)len = a;
}
int ans = 1;
for(int i = 1; i <= len; i++)
{
while(book[i]){
bool fg = false;
for(int j = 1; j <= ans; j++){
if(day[j] < i){
book[i]--;
day[j]++;
fg = true;
break;
}
}
if(!fg){
ans++;
day[ans]++;
book[i]--;
}
}
}
printf("%d\n", ans);
}

return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐