#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using pii = pair<int, int>;
int N, D, M, i, L;
vector<int> v, cnt;
bool check(int mid) {
queue<pii> q;
for(i=1; i<=N; i++) {
L = mid;
if(cnt[i]) q.push({ i, cnt[i] });
while(L && !q.empty()) {
if(i - q.front().first > D) return 0;
q.front().second--;
if(q.front().second == 0) q.pop();
L--;
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> D >> M;
v.resize(M);
cnt.resize(N+1);
for(int &x : v) cin >> x, cnt[x]++;
sort(all(v));
int l=1, r=M, ans = 0, mid;
while(l <= r) {
mid = (l + r) / 2;
if(check(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << '\n';
for(i=1; i<=N; i++) cout << 0 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1116 KB |
Output is correct |
2 |
Correct |
10 ms |
1116 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
10 ms |
1140 KB |
Output is correct |
5 |
Correct |
9 ms |
1116 KB |
Output is correct |
6 |
Correct |
10 ms |
1116 KB |
Output is correct |
7 |
Correct |
10 ms |
1116 KB |
Output is correct |
8 |
Correct |
10 ms |
1116 KB |
Output is correct |
9 |
Correct |
18 ms |
1628 KB |
Output is correct |
10 |
Correct |
18 ms |
1628 KB |
Output is correct |
11 |
Correct |
13 ms |
1112 KB |
Output is correct |
12 |
Correct |
27 ms |
1884 KB |
Output is correct |
13 |
Correct |
40 ms |
2652 KB |
Output is correct |
14 |
Correct |
61 ms |
3952 KB |
Output is correct |
15 |
Correct |
69 ms |
4176 KB |
Output is correct |
16 |
Correct |
90 ms |
5720 KB |
Output is correct |
17 |
Correct |
104 ms |
6480 KB |
Output is correct |
18 |
Correct |
119 ms |
6656 KB |
Output is correct |
19 |
Correct |
126 ms |
7760 KB |
Output is correct |
20 |
Correct |
103 ms |
6492 KB |
Output is correct |