View Code of Problem 61

#include<stdio.h>

int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int t,i;
		scanf("%d",&t);
		int a[t];
		for(i=0;i<t;i++){
			scanf("%d",&a[i]);
		}
		qsort(a,t,sizeof(a[0]),cmp);
		int max=n*a[0];
		for(i=1;i<t;i++){
			if(max<a[i]*(t-i))
			max=a[i]*(t-i);
		}
		printf("%d\n",max);
	}
}

Double click to view unformatted code.


Back to problem 61