# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387540 | ahmet | Job Scheduling (CEOI12_jobs) | C++14 | 303 ms | 23676 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.
//https://oj.uz/problem/view/CEOI12_jobs
//https://usaco.guide/silver/binary-search?lang=cpp
#include <bits/stdc++.h>
using namespace std;
#define zaman cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define endl '\n'
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define mp make_pair
const int mx=2e5+6;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,d,m;cin >> n >> d >> m;
vector <pair <int,int> > a(m);
rep(i,m){
int x;cin >> x;
a[i]=mp(x,i);
}
sort(a.begin(),a.end());
int l=1,r=1000000;
while(l<r){
int mid=(l+r)/2;
int res=mid;bool ans=true;
int day=1;
for(int i=0;i<m;++i){
int req=a[i].first;
//if(mid==500000)cout <<i<< " "<<day<< " " <<res<<" "<<req<<endl;
if(req>day){
res=mid-1;
day=req;
continue;
}
if(day>req+d){
ans=false;
break;
}
--res;
if(res==0){
day++;
res=mid;
}
}
if(ans)r=mid;
else l=mid+1;
}
int cev=l;
vector <int> b[n+1];
if(cev){
int day=1,res=cev;
for(int i=0;i<m;++i){
int req=a[i].first;
if(req>day){
res=cev-1;
day=req;
b[day].pb(a[i].second+1);
continue;
}
--res;
b[day].pb(a[i].second+1);
if(res==0){
day++;
res=cev;
}
}
cout << cev << endl;
for(int i=1;i<=n;++i){
for(int j=0;j<b[i].size();++j){
cout << b[i][j] << " " ;
}
cout<<0<<endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |