Cod sursa(job #2999202)

Utilizator SerbanCaroleSerban Carole SerbanCarole Data 10 martie 2023 17:08:24
Problema Lupul Urias si Rau Scor 12
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;

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

const int MAX = 1e5 + 1;

int l , dist[MAX] , c[MAX] , n , k , v[MAX];

struct cmp{

    bool operator()( int &a , int &b){

        return c[a] < c[b];
    }
};

priority_queue <int,vector <int>,cmp> pq;

bool comp( int &a , int &b ){

    return dist[a] > dist[b];
}

int main()
{

    cin >> n >> k >> l;

    for(int i = 1 ; i <= n ; i++){

        cin >> dist[i] >> c[i];

        v[i] = i;
    }

    sort(v+1,v+1+n,comp);

    int ind = 1;

    int the_wolf = l;

    int sum_tot = 0;

    int ia_frate = 1;

    while(ind <= n && dist[v[ind]] > k){

        cout << dist[v[ind]] << ' ';

        ind++;
    }

    while(ind <= n){

        while(ind <= n && (dist[v[ind]]+l) > k ){

            pq.push(v[ind]);

            ind++;
        }

        ind--;


        while(!pq.empty() && ia_frate){

            sum_tot += c[pq.top()];

            //cout << pq.top() << ' ';

            pq.pop();

            ia_frate--;
        }

        //cout << '\n';

        while(!pq.empty()){

            pq.pop();
        }

        l+=the_wolf;

        ia_frate++;

        ind++;
    }


    cout << sum_tot;
}