Pagini recente » Cod sursa (job #3223049) | Cod sursa (job #2511566) | Cod sursa (job #1684545) | Cod sursa (job #485928) | Cod sursa (job #331334)
Cod sursa(job #331334)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int maxn=100005;
int h[maxn],n,i,j,x,l,maxt,p;
long long s;
struct nod
{
int d;
int l;
}
a[maxn];
bool fcomp(nod a,nod b)
{
return a.d<b.d;
}
void push(int x)
{
int aux;
while(x>1&&(x>>1)&&h[x>>1]<h[x])
{
aux=h[x];
h[x]=h[x>>1];
h[x>>1]=aux;
x>>=1;
}
}
void pop(int x)
{
int aux,y=0;
while(x!=y)
{
y=x;
if((y<<1)<=p&&h[y<<1]>h[y])
x=y<<1;
if((y<<1)+1<=p&&h[(y<<1)+1]>h[x])
x=(y<<1)+1;
aux=h[x];
h[x]=h[y];
h[y]=aux;
}
}
int main()
{
f>>n>>x>>l;
maxt=-0x3f3f3f3f;
for(i=1;i<=n;++i)
f>>a[i].d>>a[i].l,a[i].d=(x-a[i].d+l)/l,maxt=max(maxt,a[i].d);
sort(a+1,a+n+1,fcomp);
i=n;
for(j=maxt;j;--j)
{
while(j==a[i].d)
{
h[++p]=a[i].l;
push(p);
--i;
}
if(p)
{
s+=h[1];
h[1]=h[p];
h[p--]=0;
pop(1);
}
}
g<<s<<"\n";
f.close();
g.close();
return 0;
}