Cod sursa(job #1465017)

Utilizator bogdanboboc97Bogdan Boboc bogdanboboc97 Data 26 iulie 2015 12:25:06
Problema Lupul Urias si Rau Scor 76
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<int> h;
pair<int,int> a[100000];
int n,x,k;
int main()
{
	in>>n>>x>>k;
	for(int i=1;i<=n;i++)in>>a[i].first>>a[i].second;
	sort(a+1,a+n+1);
	int64 sol=0;
	for(int d=0,i=1;d<=x;d+=k)
    {
        while(i<=n && a[i].first<=d)
        {
            h.push(a[i].second);
            i++;
        }
        if(!h.empty())
        {
            sol+=h.top();
            h.pop();
        }
    }
	out<<sol<<'\n';
	return 0;
}