View Code of Problem 61

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


	}
	return 0;
}

Double click to view unformatted code.


Back to problem 61