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
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int N = 1000005; 9 int a, book[N], day[N]; 10 11 int main() 12 { 13 int n; 14 while(scanf("%d", &n)!=EOF) 15 { 16 int len = 0; 17 memset(book, 0, sizeof(book)); 18 memset(day, 0, sizeof(day)); 19 for(int i = 0; i < n; i++) 20 { 21 scanf("%d", &a); 22 if(a <= n) 23 book[a]++; 24 if(a < n && a > len)len = a; 25 } 26 int ans = 1; 27 for(int i = 1; i <= len; i++) 28 { 29 while(book[i]){ 30 bool fg = false; 31 for(int j = 1; j <= ans; j++){ 32 if(day[j] < i){ 33 book[i]--; 34 day[j]++; 35 fg = true; 36 break; 37 } 38 } 39 if(!fg){ 40 ans++; 41 day[ans]++; 42 book[i]--; 43 } 44 } 45 } 46 printf("%d ", ans); 47 } 48 49 return 0; 50 }