Pagini recente » Cod sursa (job #868615) | Cod sursa (job #2552345) | Cod sursa (job #899501) | Cod sursa (job #345502) | Cod sursa (job #2525787)
#include <bits/stdc++.h>
#define Dist first
#define Lana second
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
int n,x,l;
pair <int,int> a[100001];
priority_queue <int,vector<int>,greater<int>> c;
int main()
{
in>>n>>x>>l;
for(int i=1;i<=n;i++)
in>>a[i].Dist>>a[i].Lana;
sort(a+1,a+n+1);
int i=n;
while(i && a[i].Dist>x)
i--;
for(;i;i--)
if(a[i].Dist<=x)
{
c.push(a[i].Lana);
x-=l;
}
else if(c.top()<a[i].Lana)
{
c.pop();
c.push(a[i].Lana);
}
long long sum=0;
while(!c.empty())
{
sum+=(long long)c.top();
c.pop();
}
out<<sum;
return 0;
}