Cod sursa(job #3125862)

Utilizator Stefan314159Stefan Bisti Stefan314159 Data 4 mai 2023 18:17:06
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <set>
using namespace std;

ifstream in("lupu.in");
ofstream out("lupu.out");

struct oaie{
    int D, A;

    bool operator < (const oaie &o) const {
        return D < o.D;
    }
};

priority_queue<oaie> pq; /// descrescator
priority_queue<int, vector<int>, greater<int> > h;
int N, X, L, D, A, dist = 0;

int main(){
    in >> N >> X >> L;
    for(int i=1; i<=N; i++){
        in >> D >> A;
        pq.push({D, A});
    }

    int t_c = 0;
    long long l_totala = 0;

    while(!pq.empty()){
        oaie o = pq.top();
        pq.pop();

        if(o.D + t_c * L <= X){
            h.push(o.A);
            l_totala += o.A;
            t_c++;
        }
        else{
            if(!h.empty() && o.A > h.top()){
                l_totala += o.A - h.top();
                h.pop();
                h.push(o.A);
            }
        }
    }

    out << l_totala;
}