Submission #927915

#TimeUsernameProblemLanguageResultExecution timeMemory
927915megaminionJob Scheduling (CEOI12_jobs)C++17
80 / 100
1046 ms32928 KiB
#include <bits/stdc++.h> #define pb push_back #define ins insert #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() #define endl '\n' using namespace std; using ll = long long; const int M = 1e6; const int N = 1e5; int n, d, m; int a[M], mp[N+1]; vector<int> v[N+1]; vector<int> p[N+1]; bool ok(int x, bool flag) { bool ret = true; multiset<int> s; for(int i = 1; i <= n; ++i) { v[i].clear(); for(int j = 0; j < mp[i]; ++j) { s.ins(i); } for(int j = 0; j < x; ++j) { if(s.empty()) break; ret &= i - *s.begin() <= d; if(flag) { v[i].pb(p[*s.begin()].back()); p[*s.begin()].pop_back(); } s.erase(s.begin()); } } return ret; } int main() { cin.tie(0)->sync_with_stdio(0); cin>>n>>d>>m; for(int i = 0; i < m; ++i) { cin>>a[i]; mp[a[i]]++; p[a[i]].pb(i+1); } int L = 1, R = 1e7, mid; while(L < R) { mid = L + (R - L) / 2; if(ok(mid, false)) { R = mid; } else { L = mid+1; } } cout<<L<<endl; assert(ok(L, true)); for(int i = 1; i <= n; ++i) { for(int j = 0; j < sz(v[i]); ++j) { cout<<v[i][j]; if(j + 1 != sz(v[i])) cout<<" "; else cout<<" 0"; } if(v[i].empty()) { cout<<"0"; } if(i != n) cout<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...