Pagini recente » Cod sursa (job #3041079) | Cod sursa (job #3031750) | Cod sursa (job #561628) | Cod sursa (job #2308808) | Cod sursa (job #602129)
Cod sursa(job #602129)
#include<cstdio>
#include<algorithm>
using namespace std;
long n;
long long j,x,l,nr=0,s=0,y,z;
struct oaie
{
long long dist,lana;
};
oaie a[100005];
long long h[100005];
inline bool cmp(oaie v,oaie w)
{
return v.dist<w.dist;
}
void down(int m)
{
int fiu,aux;
do
{
fiu=0;
if(m+m<=nr)
{
fiu=m+m;
if(m+m+1<=nr&&h[m+m+1]>h[fiu])
fiu=m+m+1;
}
if(fiu)
if(h[fiu]>h[m])
{
aux=h[m];
h[m]=h[fiu];
h[fiu]=aux;
}
else
fiu=0;
}while(fiu);
}
void build()
{
int m;
for(m=nr/2;m>=1;m--)
down(m);
}
int main()
{
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
long i;
scanf("%ld%ld%ld",&n,&x,&l);
for(i=1;i<=n;i++)
scanf("%lld%lld",&a[i].dist,&a[i].lana);
sort(a+1,a+1+n,cmp);
y=1;
z=x%l;
for(j=0;j<=x/l;j++)
{
for(i=y;i<=n;i++)
if(a[i].dist<=z)
h[++nr]=a[i].lana;
else
break;
build();
s+=h[1];
h[1]=0;
y=i;
z=z+l;
}
printf("%lld\n",s);
return 0;
}