View Code of Problem 61

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

	} 
	printf("\n");
	return 0;
}

Double click to view unformatted code.


Back to problem 61