Submission #92079

#TimeUsernameProblemLanguageResultExecution timeMemory
92079someone_aaJob Scheduling (CEOI12_jobs)C++17
100 / 100
189 ms19960 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; int n, d, m, x; int arr[maxn]; vector<int>v[maxn]; vector<int>result[maxn]; bool check(int x) { deque<pair<int,int> > dq; for(int i=1;i<=n;i++) { dq.pb(mp(i, arr[i])); int value = x; while(value > 0 && dq.size()) { if(dq.front().first < i - d) return false; if(dq.front().second <= value) { value -= dq.front().second; dq.front().second = 0; } else { dq.front().second -= value; value = 0; } if(dq.front().second == 0) dq.pop_front(); } while(dq.front().second == 0 && dq.size()) dq.pop_front(); } return dq.size() == 0; } void get_result(int x) { deque<pair<int,int> > dq; for(int i=1;i<=n;i++) { dq.pb(mp(i, arr[i])); int value = x; while(value > 0 && dq.size()) { if(dq.front().second <= value) { value -= dq.front().second; for(int j=0;j<dq.front().second;j++) { result[i].pb(v[dq.front().first].back()); v[dq.front().first].pop_back(); } dq.front().second = 0; } else { dq.front().second -= value; for(int j=0;j<value;j++) { result[i].pb(v[dq.front().first].back()); v[dq.front().first].pop_back(); } value = 0; } if(dq.front().second == 0) dq.pop_front(); } } for(int i=1;i<=n;i++) { for(int j:result[i]) cout<<j<<" "; cout<<"0\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>d>>m; for(int i=1;i<=m;i++) { cin>>x; arr[x]++; v[x].pb(i); } int maxv = 0; for(int i=1;i<=n;i++) { maxv = max(maxv, arr[i]); } int li = 1, ri = m; while(li < ri) { int mid = (li+ri)/2; if(check(mid)) ri = mid; else li = mid + 1; } cout<<li<<"\n"; get_result(li); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...