Pagini recente » Cod sursa (job #2803238) | Cod sursa (job #2819718) | Atasamentele paginii Rezultate Info Oltenia 2019 Proba Individuala | Cod sursa (job #2871520) | Cod sursa (job #1403651)
#include<bits/stdc++.h>
using namespace std;
const int Max=100005;
int g[Max],t[Max],ind[Max];
int h[Max],hp,hc;
int n,l,H,i,j;
long long tmax(0),x,cost(0);
bool cmp(const int &i,const int &j)
{
return t[i]>t[j];
}
void upheap(int nod)
{
int tata=nod/2;
if (!tata) return ;
if (tata>=1 && h[nod]>h[tata])
{
swap(h[nod],h[nod/2]);
upheap(tata);
}
}
void downheap(int nod)
{
int fiu=2*nod;
if (fiu>hp) return ;
if (fiu<hp && h[fiu+1]>h[fiu]) ++fiu;
if (h[fiu]<=h[nod]) return ;
swap(h[nod],h[fiu]);
downheap(fiu);
}
void sterge()
{
h[1]=h[hp--];
downheap(1);
return ;
}
void add_Heap(int value)
{
h[++hp]=value;
return ;
}
int main(void)
{
ifstream cin("gutui.in");
ofstream cout("gutui.out");
cin>>n>>H>>l;
for(i=1;i<=n;++i)
{
cin>>hc>>g[i];
ind[i]=i;
t[i]=(H-hc)/l;
tmax=max(tmax,t[i]);
}
sort(ind+1,ind+n+1,cmp);
i=1;
for(j=tmax;j>=0;--j)
{
while(t[ind[i]]==j && i<=n)
{
add_Heap(g[ind[i]]);
upheap(hp);
++i;
}
if(hp)
{
cost+=h[1];
sterge();
}
}
cout<<cost;
return 0;
}