제출 #1308275

#제출 시각아이디문제언어결과실행 시간메모리
1308275joze_plocnikJob Scheduling (CEOI12_jobs)C++20
100 / 100
86 ms14048 KiB
#include <iostream>
#include <algorithm> 
#include <vector>
#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;


int main() {
    oopt;
    int n,d,m; cin >> n >> d>>m; 
    vi naroceni(n);
    vector<vector<int>> vrednosti(n); // to ti poje malo preveč vsega (že prazen deque = 80 bytov)
    pair<int,int> pntr = {0,0}; //na katerem id-ju smo, pa kateri po vrsti tam
    
    forn(i,m){
        int t; cin >> t; naroceni[--t]++;
        vrednosti[t].push_back(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.pop_front();
                    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;
    forn(i,n){
        int mesta = rob;
        while(mesta){
            while(pntr.second >= vrednosti[pntr.first].size()){
                //preverimo, če dosti nazaj (tukaj ni treba)
                pntr.first++;
                pntr.second = 0;
                if(pntr.first > i) break; // šli smo predaleč
            }
            if(pntr.first > i) break;
            cout << vrednosti[pntr.first][pntr.second] << " "; 
            pntr.second++; 
            mesta--;
        }
        /*
        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][pntr]; pntr++;
                cout << ven << " ";
            }
            if(vrh.second == 0) {
                cakajoci.pop_front(); 
            }        
        }
        */
        cout << "0\n";
    }

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