View Code of Problem 61

#include<string.h>
#include<stdio.h>
#include<math.h>
int main(){
	int i,n,j,k;
	int t;
	int len;
	int a[1000];

	scanf("%d",&t);
	while(t--){
		int temp;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(k=0;k<n-1;k++){
			for(j=k+1;j<n;j++){
				if(a[k]>a[j]){
					temp=a[j];
					a[j]=a[k];
					a[k]=temp;
				}
			}
		}
		int max=0;
		int p;
		int sum=0;
		for(j=n,p=1;j>0,p<=n;j--,p++){
			sum=a[j]*(p-1);
		
			if(sum>max){
				max=sum;
			}
		}
		printf("%d\n",max);
		
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 61