Pagini recente » Cod sursa (job #2620688) | Cod sursa (job #2513343) | Cod sursa (job #313406) | Cod sursa (job #2571360) | Cod sursa (job #517784)
Cod sursa(job #517784)
#include <stdio.h>
#include <algorithm>
#define NMax 100000
using namespace std;
const char IN[]="lupu.in",OUT[]="lupu.out";
int N,X,L;
struct oaie{
int x,d;
} a[NMax];
bool cmp(oaie a,oaie b)
{
return a.d<b.d;
}
bool cmp2(oaie a,oaie b)
{
return a.x<b.x;
}
int main()
{
int i,p,l,ll,d,last=0,r;
long long s=0;
freopen(IN,"r",stdin);
scanf("%d%d%d",&N,&X,&L);
for (i=0;i<N;i++)
{
scanf("%d%d",&a[i].d,&a[i].x);
a[i].d= (X-a[i].d)/L + 1;
}
fclose(stdin);
sort(a,a+N,cmp);
for (p=0;p<N && a[p].d<=0;p++);
for(r=0;p<N;p+=l)
{
l=0;
d= a[p].d - last;
last= a[p].d;
for(l=0;p+l<N && a[p+l].d==a[p].d;l++);
make_heap(a+p,a+p+l,cmp2);
for (i=0,ll=l;i<d && ll>0;i++,ll--)
{
s+= a[p].x;
pop_heap(a+p,a+p+ll,cmp2);
}
for (;r>0 && ll>0;i++,l--)
{
s+= a[p].x;
pop_heap(a+p,a+p+ll,cmp2);
r--;
}
r+= d-i;
}
freopen(OUT,"w",stdout);
printf("%lld\n",s);
fclose(stdout);
return 0;
}