#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 20
const ll MOD = 998244353;
const ll MAXN = 1e6 + 100;
int N, D;
vector<vector<int>> ans;
vector<int> days[MAXN];
deque<pair<int,int>> dq;
bool check(int mid) {
dq = deque<pair<int,int>>();
ans.clear();
for (int i = 1; i <= N; i++) {
ans.emplace_back(vector<int>());
for (auto u : days[i]) {
dq.push_back({i + D, u});
}
int Q = mid;
while (Q && dq.size()) {
pair<int,int> P = dq.front();
if (P.f < i)
return false;
ans.back().push_back(P.s);
dq.pop_front();
Q--;
}
}
return dq.empty();
}
int main() {
fast
int M, Q;
cin >> N >> D >> M;
for (int i = 0; i < M; i++) {
cin >> Q;
days[Q].push_back(i+1);
}
int L = 1;
int R = M;
int res = -1;
while (R >= L) {
int mid = L + (R - L) / 2;
if (check(mid)) {
res = mid;
R = mid - 1;
} else
L = mid + 1;
}
cout << res << endl;
for (auto u : ans) {
for (auto v : u)
cout << v << " ";
cout << "0" << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
26388 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
29 ms |
26396 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
28 ms |
26332 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
28 ms |
26440 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
29 ms |
26432 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
28 ms |
26440 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
31 ms |
26360 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
30 ms |
26348 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
37 ms |
29592 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
32 ms |
29160 KB |
Unexpected end of file - int32 expected |
11 |
Correct |
31 ms |
25564 KB |
Output is correct |
12 |
Correct |
57 ms |
27228 KB |
Output is correct |
13 |
Incorrect |
80 ms |
30076 KB |
Unexpected end of file - int32 expected |
14 |
Correct |
144 ms |
32576 KB |
Output is correct |
15 |
Correct |
120 ms |
32100 KB |
Output is correct |
16 |
Runtime error |
175 ms |
35312 KB |
Memory limit exceeded |
17 |
Runtime error |
216 ms |
39204 KB |
Memory limit exceeded |
18 |
Runtime error |
224 ms |
38096 KB |
Memory limit exceeded |
19 |
Runtime error |
230 ms |
39332 KB |
Memory limit exceeded |
20 |
Runtime error |
218 ms |
39268 KB |
Memory limit exceeded |