Smart Phone

this code id giving right answer for the first three cases but wrong answer for the next three
please help

#include <stdio.h>

#include <stdlib.h>


**long** **long** **int** max_rev( **long** **long** **int** x[], **long** **long** **int** n)

{

**long** **long** **int** max=x[0],i;

**for** (i=0;i<n;i++)

**if** (x[i]>max)

max=x[i];

**return** max;

}

**void** bub_sort( **long** **long** **int** x[], **long** **long** **int** n)

{

**long** **long** **int** i,j,temp;

**for** (i=0;i<n;i++)

**for** (j=0;j<i;j++)

**if** (x[j]>x[j+1])

{

temp=x[j];

x[j]=x[j+1];

x[j+1]=temp;

}

}

**int** main()

{

**long** **long** **int** N, *bud,i;

scanf("%lld",&N);

bud=( **long** **long** **int** *)malloc(N* **sizeof** ( **long** **long** **int** ));

**for** (i=0;i<N;i++)

scanf("%lld",&bud[i]);

bub_sort(bud,N);

**for** (i=0;i<N;i++)

bud[i]*=(N-i);

printf("%lld",max_rev(bud,N));

}

Bubble sort is too slow for the given constraints. Consider using qsort(), an inbuilt quick sort.

1 Like

thnx it worked