Pagini recente » Cod sursa (job #2197976) | Cod sursa (job #122484) | Cod sursa (job #868766) | Cod sursa (job #1631019) | Cod sursa (job #2396121)
#include <iostream>
#include <queue>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
priority_queue <int> hip;
const int N=100000000;
int n,i,curent,x,l;
long long sum=0;
struct obiect{
int t;
int p;
}v[N];
int cmp(obiect a, obiect b)
{
return a.t<b.t;
}
void golire()
{
while(!hip.empty())
{
sum+=hip.top();
hip.pop();
}
}
int main()
{
in>>n>>x>>l;
for(i=1 ; i<=n ; i++)
{
in>>v[i].t>>v[i].p;
}
sort(v+1,v+n+1,cmp);
int curent=0;
for(i=n ; i>=1 ; i--)
{
if(v[i].t+curent<=x)
{
hip.push(-v[i].p);
curent+=l;
}
else
{
if(hip.top()>-v[i].p)
{
hip.pop();
hip.push(-v[i].p);
}
}
}
golire();
out<<-sum;
return 0;
}