Submission #1308255

#TimeUsernameProblemLanguageResultExecution timeMemory
1308255joze_plocnikJob Scheduling (CEOI12_jobs)C++20
40 / 100
144 ms82048 KiB
#include <iostream>
#include <algorithm> 
#include <vector>
#include <map>
#include <unordered_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; 
    unordered_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;
        deque<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.front(); cakajoci.pop_front();
                int cng = min(mesta,vrh.second);
                vrh.second -= cng;
                mesta -= cng;
                if(vrh.second != 0) cakajoci.push_front(vrh);
                else {
                    if(i - vrh.first > d) vredu = false;
                }
            }
            if(naroceni[i]-mesta > 0) cakajoci.push_back({i,naroceni[i]-mesta});   
        }
        if(vredu){
            r = rob;
        } else {
            l = rob+1;
        }
    }
    cout << l << "\n";
  
    int rob = l;
    deque<pair<int,int>> cakajoci; 
    bool vredu = true;
    forn(i,n){
        int mesta = rob;
            while(!cakajoci.empty() && mesta > 0){
            pair<int,int> vrh = cakajoci.front(); cakajoci.pop_front();
            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_front(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_back({i,novi});
        cout << "0\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...