#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 1e6 + 5;
int N, M, D;
int cnt[MX];
bool f(int x) {
deque<int> dq;
for(int i = 1; i <= N; i++) {
if(dq.size() && dq.front() < i) return 0;
for(int j = 0; j < cnt[i]; j++) dq.push_back(i + D);
for(int j = 0; j < x; j++) {
if(dq.empty()) break;
dq.pop_front();
}
}
if(dq.size()) return 0;
return 1;
}
// void p(int x) {
// deque<int> dq;
// for(int i = 1; i <= N; i++) {
// for(int j = 0; j < cnt[i]; j++) dq.push_back(i + D);
// for(int j = 0; j < x; j++) {
// if(dq.empty()) break;
// dq.pop_front();
// }
// }
// }
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> D >> M;
for(int i = 0; i < M; i++) {
int x;
cin >> x;
cnt[x]++;
}
int l = 1, r = M, ans = 0;
while(l <= r) {
int mid = (l + r) >> 1;
if(f(mid)) {
r = mid - 1, ans = mid;
} else {
l = mid + 1;
}
}
cout << ans << '\n';
for(int i = 0; i < N; i++) cout << 0 << '\n';
// p(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
876 KB |
Output is correct |
2 |
Correct |
12 ms |
872 KB |
Output is correct |
3 |
Correct |
10 ms |
920 KB |
Output is correct |
4 |
Correct |
12 ms |
876 KB |
Output is correct |
5 |
Correct |
9 ms |
872 KB |
Output is correct |
6 |
Correct |
10 ms |
864 KB |
Output is correct |
7 |
Correct |
10 ms |
876 KB |
Output is correct |
8 |
Correct |
9 ms |
876 KB |
Output is correct |
9 |
Correct |
17 ms |
548 KB |
Output is correct |
10 |
Correct |
15 ms |
532 KB |
Output is correct |
11 |
Correct |
12 ms |
348 KB |
Output is correct |
12 |
Correct |
16 ms |
348 KB |
Output is correct |
13 |
Correct |
23 ms |
472 KB |
Output is correct |
14 |
Correct |
34 ms |
604 KB |
Output is correct |
15 |
Correct |
37 ms |
348 KB |
Output is correct |
16 |
Correct |
49 ms |
344 KB |
Output is correct |
17 |
Correct |
85 ms |
484 KB |
Output is correct |
18 |
Correct |
63 ms |
500 KB |
Output is correct |
19 |
Correct |
76 ms |
452 KB |
Output is correct |
20 |
Correct |
67 ms |
348 KB |
Output is correct |