View Code of Problem 61

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

Double click to view unformatted code.


Back to problem 61