Pagini recente » Cod sursa (job #1943265) | Cod sursa (job #1883993) | Cod sursa (job #2356210) | Cod sursa (job #711403) | Cod sursa (job #138534)
Cod sursa(job #138534)
#include<stdio.h>
long int n,i,j,k,a[100002],b[100002],aux,max;
void hd(long int ic,long int nc);
void sh(long int i1,long int i2);
int main()
{
FILE *f,*g;f=fopen("heavymetal.in","r");g=fopen("heavymetal.out","w");
fscanf(f,"%ld",&n);for(i=1;i<=n;i++)fscanf(f,"%ld%ld",&a[i],&b[i]);
for(i=n/2;i>=1;i--)hd(i,n);
for(i=n;i>=1;i--){sh(1,i);hd(1,i-1);}
fprintf(g,"%ld\n",max);
fcloseall();
return 0;
}
void hd(long int ic,long int nc)
{
long int is,is1;
is=2*ic;is1=ic+1;
if(is>nc)return;
if(is<nc)if(b[is1]>b[is])is=is1;
if(b[is]>b[ic]){sh(is,ic);hd(is,nc);}
}
void sh(long int i1,long int i2)
{
aux=a[i1];a[i1]=a[i2];a[i2]=aux;
aux=b[i1];b[i1]=b[i2];b[i2]=aux;
}