Cod sursa(job #1410996)

Utilizator CostanMiriamCostan Miriam CostanMiriam Data 31 martie 2015 13:09:16
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <queue>
#include <algorithm>

#define DIM 100005
#define dist first
#define wool second

using namespace std;

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

priority_queue<int> q;

int n, l, x;

pair<int, int> v[DIM];

int main () {

    fin >> n >> x >> l;

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

         fin >> v[i].dist >> v[i].wool;

    }

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

    int pos = 1;

    long long res = 0;

    for (int crtDist = 0; crtDist <= x; crtDist += l) {

        while (pos <= n && v[pos].dist <= crtDist) {

            q.push(v[pos].wool);

            pos++;

        }

        if (q.empty())
            continue;

        res += q.top();

        q.pop();

    }

    fout << res << "\n";

    return 0;

}

//Trust me, I'm the Doctor!
//Miriam e tare!