Cod sursa(job #1464983)

Utilizator bogdanboboc97Bogdan Boboc bogdanboboc97 Data 26 iulie 2015 11:18:36
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <limits>
#include <queue>
#include <vector>
#include <algorithm>
#define INF numeric_limits<int>::max()
#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(a,b));
	}
	int d=0,sol=0;
	while(!h.empty())
	{
	    int mx=-INF;
	    while(h.top().first+d > x)h.pop();
		while(h.top().first+d+l > x && !h.empty())
        {
            mx=max(mx,h.top().second);
            h.pop();
        }
        if(mx!=-INF)sol+=mx;
		d+=l;
	}
	out<<sol<<'\n';
	return 0;
}