#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
#define deb1(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl;
#define ff first
#define ss second
#define pb push_back
int N, D, M;
pair<int, int> a[1000300];
vector<int> ans_dur;
bool ok(int m) {
int cm = 0, cd = 1;
ans_dur.clear();
for (int i = 1; i <= M; i++) {
if (cm < m) {
if (a[i].ff > cd) {
cm = 1, cd = a[i].ff;
ans_dur.pb(0); ans_dur.pb(a[i].ss);
}
else {
cm++;
ans_dur.pb(a[i].ss);
if (cd - a[i].ff > D)
return 0;
}
}
else {
cm = 1, cd++;
ans_dur.pb(0); ans_dur.pb(a[i].ss);
if (cd - a[i].ff > D)
return 0;
}
}
ans_dur.pb(0);
return 1;
}
void show() {
for (int x : ans_dur) {
if (x == 0) cout << "0\n";
else cout << x << " ";
}
}
signed main() {
FAST;
cin >> N >> D >> M;
for (int i = 1; i <= M; i++) {
cin >> a[i].ff;
a[i].ss = i;
}
sort(a + 1, a + 1 + M);
int l = 1, r = M, ans = M;
while (l <= r) {
int m = l + (r - l) / 2;
if (ok(m)) ans = m, r = m - 1;
else l = m + 1;
}
cout << ans << "\n";
show();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
3388 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
26 ms |
3284 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
27 ms |
3312 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
27 ms |
3396 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
26 ms |
3408 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
26 ms |
3396 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
26 ms |
3280 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
28 ms |
3336 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
34 ms |
3392 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
34 ms |
3284 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
37 ms |
3412 KB |
Unexpected end of file - int32 expected |
12 |
Correct |
73 ms |
6380 KB |
Output is correct |
13 |
Incorrect |
115 ms |
9524 KB |
Unexpected end of file - int32 expected |
14 |
Correct |
149 ms |
12632 KB |
Output is correct |
15 |
Correct |
184 ms |
15536 KB |
Output is correct |
16 |
Incorrect |
261 ms |
18748 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
274 ms |
21724 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
306 ms |
24740 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
363 ms |
26844 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
267 ms |
21692 KB |
Unexpected end of file - int32 expected |