Cod sursa(job #1862327)

Utilizator valentinoMoldovan Rares valentino Data 29 ianuarie 2017 19:37:22
Problema Lupul Urias si Rau Scor 48
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <vector>
#include <queue>
using namespace std;

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

priority_queue < int > heap;
int n, a[100005], t[100005],d, l, tmax;

int main()
{
    int sol = 0;
    f >> n >> d >> l;
    for(int i = 1; i<= n; ++i)
    {
        f >> t[i] >> a[i];
        t[i] = (d - t[i]) / l;
        tmax = max(tmax, t[i]);
    }
    for(int i = tmax; i >= 0; --i)
    {
        for(int j = 1; j <= n; ++j)
        {
            if(t[j] == i) heap.push(a[j]);
        }
        sol += heap.top();
        heap.pop();
    }
    g << sol << '\n';
}