#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e5 + 5;
const int M = 1e6 + 5;
vector<int>vec[N];
pii a[M];
int n,d,m;
bool check(int val) {
int day = 0,cnt = 0;
for (int i = 1; i <= m; i++) {
if (cnt == val) day++,cnt = 0;
if (day < a[i].fi) day = a[i].fi,cnt = 0;
if (day > a[i].fi && day - a[i].fi > d) return false;
cnt++;
}
if (day > n) return false;
return true;
}
int tknp(int l,int r) {
int ans = r + 1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) ans = min(ans,mid),r = mid - 1;
else l = mid + 1;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> d >> m;
for (int i = 1; i <= m; i++) {
cin >> a[i].fi;
a[i].se = i;
}
sort(a + 1,a + m + 1);
int ans = tknp(1,m);
cout << ans << "\n";
int day = 0,cnt = 0;
for (int i = 1; i <= m; i++) {
if (cnt == ans) day++,cnt = 0;
if (day < a[i].fi) day = a[i].fi,cnt = 0;
vec[day].push_back(a[i].se);
cnt++;
}
for (int i = 1; i <= n; i++) {
for (auto x: vec[i]) cout << x << " ";
cout << 0 << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
7516 KB |
Output is correct |
2 |
Correct |
16 ms |
7512 KB |
Output is correct |
3 |
Correct |
16 ms |
7516 KB |
Output is correct |
4 |
Correct |
16 ms |
7512 KB |
Output is correct |
5 |
Correct |
16 ms |
7516 KB |
Output is correct |
6 |
Correct |
17 ms |
7516 KB |
Output is correct |
7 |
Correct |
15 ms |
7512 KB |
Output is correct |
8 |
Correct |
16 ms |
7516 KB |
Output is correct |
9 |
Correct |
27 ms |
7772 KB |
Output is correct |
10 |
Correct |
27 ms |
7764 KB |
Output is correct |
11 |
Correct |
23 ms |
7504 KB |
Output is correct |
12 |
Correct |
44 ms |
8824 KB |
Output is correct |
13 |
Correct |
67 ms |
12368 KB |
Output is correct |
14 |
Correct |
97 ms |
14160 KB |
Output is correct |
15 |
Correct |
116 ms |
13948 KB |
Output is correct |
16 |
Correct |
142 ms |
17264 KB |
Output is correct |
17 |
Correct |
168 ms |
20500 KB |
Output is correct |
18 |
Correct |
187 ms |
20116 KB |
Output is correct |
19 |
Correct |
213 ms |
20884 KB |
Output is correct |
20 |
Correct |
171 ms |
20336 KB |
Output is correct |