View Code of Problem 61

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

Double click to view unformatted code.


Back to problem 61