View Code of Problem 61

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

}

Double click to view unformatted code.


Back to problem 61