Cod sursa(job #1862338)

Utilizator valentinoMoldovan Rares valentino Data 29 ianuarie 2017 19:44:13
Problema Lupul Urias si Rau Scor 72
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 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;
        t = (d - t) / l;
        v[t].push_back(a);
        tmax = max(tmax, t);
    }
    for(int i = tmax; i >= 0; --i)
    {
        for(int j = 0; j < v[i].size(); ++j)
        {
           heap.push(v[i][j]);
        }
        sol += heap.top();
        heap.pop();
    }
    g << sol << '\n';
}