#include <bits/stdc++.h>
#define fr first
#define se second
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define repr(i,a,b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IN(i,l,r) (l<i&&i<r)
#define pb push_back
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef long long ll;
const int U = 1e6+2;
int N,D,M;
pi job[U];
pair<bool,vector<vi>> check(int m){
vector<vi> s(N);
int t=0;
rep(day,1,N+1){
rep(i,0,m){
if(job[t].fr > day){
break;
}
if(job[t].fr + D >= day){
s[day-1].pb(job[t].se);
++t;
}else{
return {false,s};
}
if(t==M) return {true,s};
}
}
return {false,s};
}
int main(){
cin.tie(0)->sync_with_stdio(false);
cin >> N >> D >> M;
rep(i,0,M){
cin >> job[i].fr;
job[i].se = i+1;
}
sort(job,job+M);
int lo=1,hi=M;
vector<vi> s;
while(lo < hi){
ll m = (lo+hi)/2;
pair<bool,vector<vi>> res = check(m);
if(res.fr){
hi = m;
s = res.se;
}else{
lo = m+1;
}
}
cout << hi << '\n';
for(auto &v:s){
for(auto &e:v){
cout << e << ' ';
}
cout << "0\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4628 KB |
Output is correct |
2 |
Correct |
26 ms |
4628 KB |
Output is correct |
3 |
Correct |
22 ms |
4628 KB |
Output is correct |
4 |
Correct |
22 ms |
4624 KB |
Output is correct |
5 |
Correct |
23 ms |
4808 KB |
Output is correct |
6 |
Correct |
22 ms |
4592 KB |
Output is correct |
7 |
Correct |
21 ms |
4592 KB |
Output is correct |
8 |
Correct |
22 ms |
4628 KB |
Output is correct |
9 |
Correct |
57 ms |
11288 KB |
Output is correct |
10 |
Correct |
59 ms |
11252 KB |
Output is correct |
11 |
Correct |
28 ms |
4160 KB |
Output is correct |
12 |
Correct |
67 ms |
5740 KB |
Output is correct |
13 |
Correct |
82 ms |
10596 KB |
Output is correct |
14 |
Correct |
135 ms |
11928 KB |
Output is correct |
15 |
Correct |
155 ms |
11376 KB |
Output is correct |
16 |
Correct |
205 ms |
17744 KB |
Output is correct |
17 |
Correct |
244 ms |
19792 KB |
Output is correct |
18 |
Correct |
251 ms |
23428 KB |
Output is correct |
19 |
Correct |
321 ms |
26872 KB |
Output is correct |
20 |
Correct |
251 ms |
19580 KB |
Output is correct |