Pagini recente » Cod sursa (job #305854) | Cod sursa (job #2235937) | Cod sursa (job #1777705) | Cod sursa (job #2030164) | Cod sursa (job #1815547)
#include <cstdio>
#include <algorithm>
using namespace std;
pair <int,int> v[100001];
int h[100001];
int cmp (pair <int,int> a,pair <int,int> b){
return a.first>b.first;
}
void adauga (int i,int elem){
int p,c,aux;
h[elem]=v[i].second;
c=elem;
p=elem/2;
while (p>0){
if (h[c]>h[p]){
aux=h[c];
h[c]=h[p];
h[p]=aux;
}
else break;
c=p;
p/=2;
}
}
void sterge (int poz,int &elem){
int p,c,aux;
h[poz]=h[elem];
elem--;
p=poz;
c=2*poz;
while (c<=elem){
if (c+1<=elem && h[c+1]>h[c])
c++;
if (h[p]<h[c]){
aux=h[c];
h[c]=h[p];
h[p]=aux;
}
else break;
p=c;
c*=2;
}
}
int main()
{
FILE *fin=fopen ("lupu.in","r");
FILE *fout=fopen ("lupu.out","w");
int n,x,l,i,elem=0,j,m=0,a,b,maxi=0;
long long sol=0;
fscanf (fin,"%d%d%d",&n,&x,&l);
for (i=1;i<=n;i++){
fscanf (fin,"%d%d",&a,&b);
if (x>=a){
m++;
v[m].first=(x-a)/l+1;
v[m].second=b;
maxi=max(maxi,v[m].first);
}
// dupa v[i].first alegeri, oaia i va disparea
}
sort (v+1,v+m+1,cmp);
j=1;
for (i=maxi;i>0;i--){
while (v[j].first==i){
elem++;
adauga (j,elem);
j++;
}
if (elem>0){
sol+=h[1];
sterge (1,elem);
}
}
fprintf (fout,"%lld",sol);
return 0;
}