View Code of Problem 61

#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	
	int t;
	int n;
	scanf("%d", &t);
	while( t-- ){
		scanf("%d", &n );
		int arr[n];
		for( int i=0; i<n; i++ ){
			scanf("%d", &arr[i] );
		}
		sort(arr,arr+n);
		int max = arr[0]*n;
		for( int i=1; i<n; i++ ){
			int s = arr[i]*(n-i);
			if( s> max ){
				max = s;
			}
		}
		printf("%d\n", max );
	
	}
	
	return 0;
	
}

Double click to view unformatted code.


Back to problem 61