View Code of Problem 61

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

Double click to view unformatted code.


Back to problem 61