Pagini recente » Cod sursa (job #2037988) | Cod sursa (job #1955788) | Cod sursa (job #2148896) | Cod sursa (job #135899) | Cod sursa (job #1389794)
#include <iostream>
#include <cstdio>
#include <algorithm>
#define nmax 100005
using namespace std;
int n,x,len,m,best;
long long sum;
struct Coord{
int d,b;
};
Coord a[nmax];
inline bool cmp(const Coord A,const Coord B){
if(A.d == B.d) return A.b > B.b;
return A.d > B.d;
}
int main(){
int i,j,ok;
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",&a[i].d,&a[i].b);
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;i++){
best=ok=0;
if(a[i].d + len*m <= x){
if(a[i].d + len*m + len <= x){m++;sum+=a[i].b;continue;}
j=i;
while(a[j].d+len*m <= x && a[j].d+len*m+len > x&&j<=n){
best=max(best,a[j].b);
j++;
}
i=j-1;
if(best){
m++;
sum+=best;
}
}}
cout<<sum<<'\n';
return 0;
}