# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480510 | imaginary_unit | Job Scheduling (CEOI12_jobs) | C++17 | 718 ms | 19888 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>
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
int n, d, m, temp;
vector<vector<int> > a(100'001);
bool ok(int mch)
{
priority_queue<int, vector<int>, greater<int> > pq;
for(int i=1; i<=n; i++){
for(int j=0; j<a[i].size(); j++){
pq.push(i+d);
}
for(int j=0; j<mch; j++){
if(pq.empty()){
break;
}
if(pq.top() < i){
return 0;
}
pq.pop();
}
}
return 1;
}
int minMachines(int l, int r)
{
while(r-l>1){
int m=(l+r)/2;
if(ok(m)){
r=m;
}
else{
l=m;
}
}
return r;
}
int main()
{
//freopen("angry.in", "r", stdin);
//freopen("angry.out", "w", stdout);
scanf("%d %d %d", &n, &d, &m);
for(int i=1; i<=m; i++){
scanf("%d", &temp);
a[temp].push_back(i);
}
int ans=minMachines(1, m);
cout << ans << '\n';
vector<vector<int> > tasks(n+1);
priority_queue<pii, vector<pii>, greater<pii> > pq;
for(int i=1; i<=n; i++){
for(int j=0; j<a[i].size(); j++){
pq.push({i+d, a[i][j]});
}
for(int j=0; j<ans; j++){
if(pq.empty()){
break;
}
tasks[i].push_back(pq.top().se);
pq.pop();
}
}
for(int i=1; i<=n; i++){
for(int j=0; j<tasks[i].size(); j++){
cout << tasks[i][j] << ' ';
}
cout << 0 << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |