Pagini recente » Cod sursa (job #1598729) | Cod sursa (job #2069838) | Cod sursa (job #2415748) | Cod sursa (job #1622068) | Cod sursa (job #1389928)
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <queue>
#define nmax 100005
using namespace std;
int n,x,len,m,best;
long long sum;
struct Coord{
int d,b;
};
Coord a[nmax];
priority_queue<int>q;
inline bool cmp(const Coord A,const Coord B){
return A.d < B.d;
}
int main(){
int i,j,xx,yy;
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
scanf("%d%d%d",&n,&x,&len);
for(i=1;i<=n;i++){
scanf("%d%d",&xx,&yy);
if(xx<=x)
a[++m].d = (x-xx) / len+1,a[m].b=yy;
}
n=m;
sort(a+1,a+n+1,cmp);
j=n;
for(i=n,j=a[n].d;j;j--){
while(i && a[i].d == j) q.push(a[i].b),i--;
if(!q.empty()){
sum+=q.top();
q.pop();
}
}
cout<<sum<<'\n';
return 0;
}