#include<bits/stdc++.h>
using namespace std;
struct job{
int time;
int arr;
int idx;
bool operator < (const job & other){
return time < other.time;
}
};
job a[1000010];
int n, m, d;
bool check(int k){
int curtime = 1;
int temp = 0;
for(int i = 1; i <= m; i++){
temp++;
if(curtime > n) return false;
if(a[i].time < curtime){
return false;
}
if(a[i].arr > curtime){
curtime = a[i].arr;
temp = 0;
continue;
}
if(temp % k == 0) curtime++;
}
return true;
}
vector<vector<int>> ans(100010);
bool cmp(int a, int b){
return a > b;
}
int main(){
cin >> n >> d >> m;
for(int i = 1; i <= m; i++){
cin >> a[i].arr;
a[i].time = a[i].arr+d;
a[i].idx = i;
}
sort(a+1, a+m+1);
int l = 1, r = m;
int mid;
int num = m;
while(l <= r){
mid = (l+r)/2;
if(check(mid) == true){
num = mid;
r = mid-1;
}else{
l = mid+1;
}
}
cout << num << endl;
int cnt = 1;
int temp = 0;
for(int i = 1; i <= m; i++){
ans[cnt].push_back(a[i].idx);
temp++;
if(a[i].arr > cnt){
cnt = a[i].arr;
temp = 0;
continue;
}
if(temp % num == 0) cnt++;
}
for(int i = 1; i <= n; i++){
for(auto j : ans[i]){
cout << j << " ";
}
cout << "0\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |