Cod sursa(job #1862848)

Utilizator valentinoMoldovan Rares valentino Data 30 ianuarie 2017 12:41:13
Problema Lupul Urias si Rau Scor 88
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <vector>
#include <queue>
using namespace std;

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

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

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