View Code of Problem 61

#include <stdio.h>
#include <math.h>
int main()
{
    int n,t;
    scanf("%d",&t);
    while(t--){
        
        scanf("%d",&n);
        int a[n];
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                if(a[j]<a[i]){
                    int temp=a[j];
                    a[j]=a[i];
                    a[i]=temp;
                }
            }
        }
        int max=a[0];
        for(int i=0;i<n;i++){
            if((a[i]*(n-i))>max)
                max=a[i]*(n-i);
        }
        printf("%d\n",max );
        
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 61