#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
const int N = 2e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;
#define X first
#define Y second
signed main(){
ios::sync_with_stdio(false); cin.tie(0);
int n, d, m; cin >> n >> d >> m;
pair<int, int> p[m];
for(int i = 0; i < m; i++){
cin >> p[i].first; p[i].second = i + 1;
}
sort(p, p + m);
int l = 0, r = INF;
vector<int> work(n);
while(r - l > 1){
int mid = l + r >> 1;
int pos = 0;
bool ok = 1;
for(int i = 0; i < n; i++){
int cnt = 0;
while(pos < m && cnt < mid && p[pos].first <= i + 1) pos++, cnt++;
work[i] = cnt;
if(pos < m && p[pos].first <= i - d + 1) ok = 0;
}
if(pos < m) ok = 0;
if(ok) r = mid;
else l = mid;
}
int pos = 0;
cout << r << '\n';
for(int i = 0; i < n; i++){
int cnt = 0;
while(pos < m && cnt < r && p[pos].first <= i + 1) cout << p[pos].second << ' ', pos++, cnt++;
cout << "0\n";
}
}
Compilation message
jobs.cpp: In function 'int main()':
jobs.cpp:19:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2508 KB |
Output is correct |
2 |
Correct |
18 ms |
2508 KB |
Output is correct |
3 |
Correct |
21 ms |
2452 KB |
Output is correct |
4 |
Correct |
24 ms |
2460 KB |
Output is correct |
5 |
Correct |
18 ms |
2468 KB |
Output is correct |
6 |
Correct |
17 ms |
2508 KB |
Output is correct |
7 |
Correct |
18 ms |
2508 KB |
Output is correct |
8 |
Correct |
17 ms |
2508 KB |
Output is correct |
9 |
Correct |
33 ms |
3468 KB |
Output is correct |
10 |
Correct |
30 ms |
3396 KB |
Output is correct |
11 |
Correct |
25 ms |
2372 KB |
Output is correct |
12 |
Correct |
52 ms |
4676 KB |
Output is correct |
13 |
Correct |
75 ms |
6920 KB |
Output is correct |
14 |
Correct |
113 ms |
9240 KB |
Output is correct |
15 |
Correct |
128 ms |
11456 KB |
Output is correct |
16 |
Correct |
161 ms |
13796 KB |
Output is correct |
17 |
Correct |
199 ms |
16108 KB |
Output is correct |
18 |
Correct |
210 ms |
18372 KB |
Output is correct |
19 |
Correct |
267 ms |
21572 KB |
Output is correct |
20 |
Correct |
190 ms |
16068 KB |
Output is correct |