#include <bits/stdc++.h>
using namespace std;
//#define int long long
int n,d,m;
vector<int> a,index_v;
bool is_ok(int machine)
{
int ptr=0;
for(int day=1;day<=n;++day)
{
for(int i=0;i<machine;++i)
{
if(ptr>=a.size()) return true;
if(a[ptr]>day) break;
if(a[ptr]+d<day) return false;
++ptr;
}
}
return (ptr>=a.size());
}
void yes(int machine)
{
int ptr=0;
for(int day=1;day<=n;++day)
{
for(int i=0;i<machine;++i)
{
if(ptr>=index_v.size()||a[ptr]>day) break;
cout<<index_v[ptr++]<<' ';
}
cout<<0<<'\n';
}
}
main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>d>>m;
vector<pair<int,int>> tmp(m);
for(int i=0;i<m;++i) cin>>tmp[i].first,tmp[i].second=i+1;
sort(tmp.begin(),tmp.end());
for(auto it:tmp) a.push_back(it.first),index_v.push_back(it.second);
int l=0,r=1e9,ans=1e9;
while(l<=r)
{
int mid=(r-l)/2+l;
if(is_ok(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans<<'\n';
yes(ans);
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
Compilation message
jobs.cpp: In function 'bool is_ok(int)':
jobs.cpp:13:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if(ptr>=a.size()) return true;
| ~~~^~~~~~~~~~
jobs.cpp:19:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | return (ptr>=a.size());
| ~~~^~~~~~~~~~
jobs.cpp: In function 'void yes(int)':
jobs.cpp:28:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(ptr>=index_v.size()||a[ptr]>day) break;
| ~~~^~~~~~~~~~~~~~~~
jobs.cpp: At global scope:
jobs.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2768 KB |
Output is correct |
2 |
Correct |
16 ms |
2764 KB |
Output is correct |
3 |
Correct |
20 ms |
2768 KB |
Output is correct |
4 |
Correct |
17 ms |
2768 KB |
Output is correct |
5 |
Correct |
19 ms |
2764 KB |
Output is correct |
6 |
Correct |
20 ms |
2772 KB |
Output is correct |
7 |
Correct |
21 ms |
2648 KB |
Output is correct |
8 |
Correct |
16 ms |
2768 KB |
Output is correct |
9 |
Correct |
26 ms |
3024 KB |
Output is correct |
10 |
Correct |
26 ms |
3024 KB |
Output is correct |
11 |
Correct |
22 ms |
2768 KB |
Output is correct |
12 |
Correct |
44 ms |
5096 KB |
Output is correct |
13 |
Correct |
67 ms |
7292 KB |
Output is correct |
14 |
Correct |
93 ms |
9652 KB |
Output is correct |
15 |
Correct |
115 ms |
11884 KB |
Output is correct |
16 |
Correct |
160 ms |
16744 KB |
Output is correct |
17 |
Correct |
160 ms |
17316 KB |
Output is correct |
18 |
Correct |
182 ms |
18588 KB |
Output is correct |
19 |
Correct |
205 ms |
21088 KB |
Output is correct |
20 |
Correct |
161 ms |
17836 KB |
Output is correct |