Pagini recente » Cod sursa (job #1747076) | Cod sursa (job #2775300) | Cod sursa (job #1104508) | Cod sursa (job #2883367) | Cod sursa (job #1026945)
#include <cstdio>
#include <algorithm>
using namespace std;
FILE *in ,*out;
struct lupul
{
int dt,lana;
};
const int N = 100004;
lupul v[N];
int h[N],hn,n,x,l;
bool cmp (lupul x , lupul y)
{
if(x.dt > y.dt)
return 0;
return 1;
}
void schimb (int x,int y)
{
int aux = h[x];
h[x] = h[y];
h[y] = aux;
}
void urca(int i)
{
while(i>1 && h[i]<h[i/2])
{
schimb(i,i/2);
i/=2;
}
}
void coboara(int i)
{
int fs=2*i,fd=2*i+1;
int bun=i;
if(fs<=hn && h[fs]<h[bun]) bun=fs;
if(fd<=hn && h[fd]<h[bun]) bun=fd;
if(bun!=i)
{
schimb(bun,i);
coboara(bun);
}
}
void afisare()
{
long long rez=0;
for(int i = 1 ; i <= hn ; i++)
rez+=h[i];
fprintf(out,"%lld\n",rez);
}
void rezolvare()
{
int i;
hn=0;
sort(v+1,v+n+1,cmp);
int d = 0;
for(i=1 ; i<=n ; i++)
{
d+=(v[i].dt-v[i-1].dt);
if(d > 0)
{
h[++hn]=v[i].lana;
urca(hn);
d--;
}
else
if(h[1]<v[i].lana && hn>0)
{
h[1]=v[i].lana;
coboara(1);
}
}
}
void citire ()
{
fscanf(in,"%d%d%d",&n,&x,&l);
for(int i = 1 ; i<=n ; i++){
fscanf(in,"%d%d",&v[i].dt,&v[i].lana);
if(v[i].dt > x)
v[i].dt = 0;
else
v[i].dt = (x-v[i].dt)/l+1;
}
}
int main()
{
in = fopen("lupu.in","r");
out = fopen("lupu.out","w");
citire();
rezolvare();
afisare();
return 0;
}