Pagini recente » Cod sursa (job #570700) | Cod sursa (job #727252) | Cod sursa (job #2466486)
#include <bits/stdc++.h>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct wow
{
int x,cost;
}v[100005];
bool compare (wow a,wow b)
{
return a.x<b.x||(a.x==b.x&&a.cost<b.cost);
}
priority_queue <pair <int,int> > h;
int n,i,dr,nr,l,d,init,x;
long long sum;
int main()
{
f>>n>>l>>x;
for (i=1;i<=n;i++)
{
f>>v[i].x>>v[i].cost;
}
sort (v+1,v+n+1,compare);
dr=n;
nr=0;
init=l;
while (l>=0)
{
while (v[dr].x>l-x&&dr>=1)
{
h.push({v[dr].cost,v[dr].x});
dr--;
}
while (nr*x+h.top().second>init)
{
h.pop();
}
sum=sum+h.top().first;
h.pop();
l=l-x;
nr++;
}
g<<sum;
return 0;
}