Pagini recente » Cod sursa (job #1653673) | Cod sursa (job #2903116) | Cod sursa (job #2762035) | Cod sursa (job #2463697) | Cod sursa (job #1404199)
#include<bits/stdc++.h>
using namespace std;
const int Max=100005;
int h[Max],hp,hc;
int n,l,H,i,j,gr;
int tmax(0),x;
long long cost(0);
struct gutui
{
int time;
int weight;
} G[Max];
bool cmp(const gutui &i,const gutui &j)
{
return i.time>j.time;
}
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;
upheap(hp);
return ;
}
int main(void)
{
ifstream cin("gutui.in");
ofstream cout("gutui.out");
cin>>n>>H>>l;
for(i=1;i<=n;++i)
{
cin>>hc>>gr;
int timp=(H-hc)/l;
G[i]={timp,gr};
tmax=max(tmax,timp);
}
sort(G+1,G+n+1,cmp);
i=1;
for(j=tmax;j>=0;--j)
{
while(G[i].time==j && i<=n)
{
add_Heap(G[i].weight);
++i;
}
if(hp)
{
cost+=h[1];
sterge();
}
}
cout<<cost;
return 0;
}