Pagini recente » Cod sursa (job #533469) | Cod sursa (job #1746036) | Cod sursa (job #649941) | Cod sursa (job #1454514) | Cod sursa (job #2069677)
#include <bits/stdc++.h>
#define Nmax 100001
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
pair <int,int> v[Nmax];
priority_queue <int> pq;
inline bool cmp(const pair <int,int> &x, const pair <int,int> &y)
{
if(x.first==y.first)
return x.second>y.second;
else return x.first>y.first;
}
int main()
{
int n,x,l,i,lsh,rsh,N=0;
f>>n>>x>>l;
for(i=1;i<=n;i++)
{
f>>lsh>>rsh;
if(lsh<=x) v[++N]={(x-lsh)/l,rsh};
}
sort(v+1,v+N+1,cmp);
long long ans=0;
int j=1;
for(i=v[1].first;i>=0;i--)
{
for(;j<=N and i==v[j].first;)
{
pq.push(v[j].second);
j++;
}
if(!pq.empty())
{
ans+=1LL*pq.top();
pq.pop();
}
}
g<<ans;
return 0;
}