# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951623 | doducanh | Job Scheduling (CEOI12_jobs) | C++14 | 1000 ms | 29284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
const int maxn=1e5+7;
vector<int>a[maxn];
vector<int>ans[maxn];
vector<int>ress[maxn];
int n,d,m;
bool check(int x)
{
priority_queue<ii,vector<ii>,greater<ii>>q;
for(int i=1;i<=n;i++)ans[i].clear();
for(int i=1;i<=n;i++){
for(int x:a[i])q.push({i,x});
while(ans[i].size()<x&&q.size()){
if(i-q.top().fi>d)return false;
ans[i].push_back(q.top().se);
q.pop();
}
}
if(q.size())return false;
for(int i=1;i<=n;i++){
ress[i].clear();
for(int x:ans[i])ress[i].push_back(x);
ress[i].push_back(0);
}
return true;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>d>>m;
for(int i=1;i<=m;i++){
int x;
cin>>x;
a[x].push_back(i);
}
int l=0,r=m;
int res=m;
while(l<=r){
int m=(l+r)/2;
if(check(m)){
res=m;
r=m-1;
}
else l=m+1;
}
cout<<res<<"\n";
for(int i=1;i<=n;i++){
for(int x:ress[i])cout<<x<<" ";
cout<<"\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |