View Code of Problem 61

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n, k = 0, sum = 0, max;
		cin >> n;
		int a[n];
		for(int i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);
		max = a[n - 1];
		for(int i = n - 1; i >= 0; i--)
		{
			k++;
			sum = a[i] * k;
			if(sum > max)
				max = sum;
		}
		cout << max << endl;
	}
	
	return 0;
}


Double click to view unformatted code.


Back to problem 61