

#include <stdio.h>
#define H 500000
  
int A[H],n;
 
void maxHeapify(int *A,int i){
 
  int largest,l,r,temp;
 
  l = 2*i;
  r = (2*i)+1;
 
  if(l<=n && A[l]>A[i])
    largest = l;
  else
    largest = i;
 
  if(r<=n && A[r]>A[largest])
    largest = r;
   
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A,largest);
  }
}
 
void buildMaxHeap(int *A){
 
  int i;
 
  for(i=n/2;i>0;i--){
    maxHeapify(A,i);
  }
}
 
 
int main(void){
  
  int k,p,l,r,i;
 
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
    buildMaxHeap(A);
 
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 6/6 	C 	CPU: 00.10 sec 	Memory: 2552 KB 	Length: 662 B 	2015-06-19 10:36 	2015-06-19 10:36
Results for testcases
Case # 	Verdict 	CPU Time 	Memory 	In 	Out 	Case Name
Case #1: 	: Accepted 	00.00 sec 	600 KB 	8 B 	7 B 	1.in
Case #2: 	: Accepted 	00.00 sec 	600 KB 	30 B 	28 B 	2.in
Case #3: 	: Accepted 	00.00 sec 	600 KB 	62 B 	60 B 	3.in
Case #4: 	: Accepted 	00.00 sec 	596 KB 	296 B 	293 B 	4.in
Case #5: 	: Accepted 	00.00 sec 	604 KB 	3898 B 	3894 B 	5.in
Case #6: 	: Accepted 	00.10 sec 	2552 KB 	3388902 B 	3388896 B 	6.in
< prev | 	1 	/ 	6 	| next > 	  		 : Accepted        00.00 sec        600 KB
 
Judge Input #1 ( in1.txt | 8 B) 		Judge Output #1 ( out1.txt | 7 B)

3
1 2 3

		

 3 2 1

Comments
 
 Under Construction.
 
Categories
 
 
Free Tags
 
 