#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> arr;
int n, m, d;
vector<vector<int>> day;
bool f(int mm){
int del = 0;
day.clear();
day.resize(n+1);
queue<int> mac;
for(int i=0;i<mm;i++) mac.push(1);
for(int i=0;i<m;i++){
int r = mac.front();
del = max(r - arr[i].first, del);
if(del > d) return false;
day[max(r, arr[i].first)].push_back(arr[i].second);
mac.pop();
mac.push(max(r, arr[i].first)+1);
}
return true;
}
int main(){
cin>>n>>d>>m;
arr.resize(m);
for(int i=0;i<m;i++){
arr[i].second = i;
cin>>arr[i].first;
}
sort(arr.begin(), arr.end());
int mm;
int r = m;
int l = 1;
int ans = m;
while(r >= l){
mm = l + (r - l)/2;
if(f(mm)){
r = mm - 1;
ans = mm;
}
else{
l = mm + 1;
}
}
f(ans);
cout<<ans<<endl;
for(int i=1;i<n+1;i++){
for(auto t : day[i]) cout<<t+1<<" ";
cout<<"0\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2912 KB |
Output is correct |
2 |
Correct |
36 ms |
2988 KB |
Output is correct |
3 |
Correct |
45 ms |
3104 KB |
Output is correct |
4 |
Correct |
35 ms |
2992 KB |
Output is correct |
5 |
Correct |
44 ms |
2988 KB |
Output is correct |
6 |
Correct |
35 ms |
2988 KB |
Output is correct |
7 |
Correct |
35 ms |
2992 KB |
Output is correct |
8 |
Correct |
35 ms |
2832 KB |
Output is correct |
9 |
Correct |
45 ms |
4928 KB |
Output is correct |
10 |
Correct |
52 ms |
4888 KB |
Output is correct |
11 |
Correct |
45 ms |
2484 KB |
Output is correct |
12 |
Correct |
83 ms |
4224 KB |
Output is correct |
13 |
Correct |
128 ms |
6984 KB |
Output is correct |
14 |
Correct |
190 ms |
9020 KB |
Output is correct |
15 |
Correct |
232 ms |
9592 KB |
Output is correct |
16 |
Correct |
275 ms |
12804 KB |
Output is correct |
17 |
Correct |
342 ms |
16020 KB |
Output is correct |
18 |
Correct |
359 ms |
16484 KB |
Output is correct |
19 |
Correct |
403 ms |
20220 KB |
Output is correct |
20 |
Correct |
332 ms |
16128 KB |
Output is correct |