Cod sursa(job #2784044)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 15 octombrie 2021 17:14:31
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

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

struct oaie{
    int p;
    int l;
} v[100005];
bool cmp(const oaie a, const oaie b){
    return a.p < b.p;
}

priority_queue <int> q;
long long lana;
int n, m, x, d;
int pozitie, cant;

int main (){
    fin>>n>>x>>d;
    for(int i=1; i<=n; i++)
        fin>>v[i].p>>v[i].l;
    sort(v+1, v+n+1, cmp);

    int poz=1;
    for(int i=0; i<=x; i+=d){

        while(poz <= n && v[poz].p <= i){
            q.push(v[poz].l);
            poz++;
        }

        if(!q.empty()){
            lana += q.top();
            q.pop();
        }
    }

    fout<<lana;
    return 0;
}
/**
10 6 2
1 13
4 14
4 3
6 7
0 7
5 16
3 16
4 10
4 18
3 16

->

0 7
1 13
3 16
3 16
4 14
4 3
4 10
4 18
5 16
6 7
**/