Cod sursa(job #1464760)

Utilizator bogdanboboc97Bogdan Boboc bogdanboboc97 Data 24 iulie 2015 15:31:52
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <limits>
#include <queue>
#include <vector>
#include <algorithm>
#define int64 long long
#define pb push_back
#define mp make_pair
#define mod(x) ( (x) > 0 ? (x) : (-x) )
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
priority_queue< pair<int,int> > h;
int n,x,l;
int main()
{
    in>>n>>x>>l;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        in>>a>>b;
        h.push(mp(b,a));
    }
    int d=0,sol=0;
    while(!h.empty())
    {
        while(-h.top().second+d > x && !h.empty())h.pop();
        if(!h.empty())
        {
            sol+=h.top().first;
            h.pop();
        }
        d+=l;
    }
    out<<sol<<'\n';
    return 0;
}