#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 1e6 + 10;
int N, D, M;
int S[MAX_M], id[MAX_M];
bool solve(int mid) {
int i = 1;
for(int days = 1; days <= N and i <= M; days++) {
if(days > S[id[i]] + D) {
break;
}
int cnt = mid;
while(i <= M and S[id[i]] <= days and cnt--) {
i++;
}
}
return i == M + 1;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> N >> D >> M;
for(int i = 1; i <= M; i++) {
cin >> S[i];
id[i] = i;
}
sort(id + 1, id + M + 1, [&](const int &a, const int &b) {
return S[a] < S[b];
});
int l = 1, r = M, ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(solve(mid) == true) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
cout << ans << '\n';
/*for(int i = 1, j = 1; i <= N; i++) {
for(int k = 0; j <= M and k < ans; j++, k++) {
cout << id[j] << ' ';
}
cout << "0\n";
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1420 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
8 ms |
1364 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
8 ms |
1368 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
9 ms |
1424 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
8 ms |
1412 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
8 ms |
1368 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
8 ms |
1348 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
8 ms |
1364 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
10 ms |
1304 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
11 ms |
1364 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
14 ms |
1516 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
29 ms |
2724 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
45 ms |
3800 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
70 ms |
5340 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
71 ms |
6096 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
115 ms |
7816 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
128 ms |
9120 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
121 ms |
9568 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
145 ms |
10676 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
121 ms |
9072 KB |
Unexpected end of file - int32 expected |