Submission #1308252

#TimeUsernameProblemLanguageResultExecution timeMemory
1308252joze_plocnikJob Scheduling (CEOI12_jobs)C++20
40 / 100
318 ms82176 KiB
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <queue> #define vi vector<int> #define vpii vector<pair<int,int>> #define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false); #define forn(i,n) for(int i = 0; i<n; i++) #define sz(x) (x).size() using namespace std; signed main() { oopt; int n,d,m; cin >> n >> d>>m; map<int,int> naroceni; vector<queue<int>> id(n-d); forn(i,m){ int t; cin >> t; naroceni[--t]++; id[t].push(i+1); } int l = 1, r= 1e6; while(l<r){ int rob = (l+r)/2; priority_queue<pair<int,int>, vpii, greater<pair<int,int>>> cakajoci; // prvo je od kdaj, drugo je koliko jih je bool vredu = true; forn(i,n){ int mesta = rob; while(!cakajoci.empty() && mesta > 0){ pair<int,int> vrh = cakajoci.top(); cakajoci.pop(); int cng = min(mesta,vrh.second); vrh.second -= cng; mesta -= cng; if(vrh.second != 0) cakajoci.push(vrh); else { if(i - vrh.first > d) vredu = false; } } if(naroceni[i]-mesta > 0) cakajoci.push({i,naroceni[i]-mesta}); } if(vredu){ r = rob; } else { l = rob+1; } } cout << l << "\n"; int rob = l; priority_queue<pair<int,int>, vpii, greater<pair<int,int>>> cakajoci; bool vredu = true; forn(i,n){ int mesta = rob; while(!cakajoci.empty() && mesta > 0){ pair<int,int> vrh = cakajoci.top(); cakajoci.pop(); int cng = min(mesta,vrh.second); vrh.second -= cng; mesta -= cng; forn(_,cng){ int ven = id[vrh.first].front(); id[vrh.first].pop(); cout << ven << " "; } if(vrh.second != 0) cakajoci.push(vrh); else { if(i - vrh.first > d) vredu = false; } } int novi = naroceni[i]; while(mesta > 0 && novi > 0){ int ven = id[i].front(); id[i].pop(); cout << ven << " "; novi--; mesta--; } if(novi) cakajoci.push({i,novi}); cout << "0\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...