View Code of Problem 61

#include<stdio.h>
#include<string.h>
int main() {
	int t, i, j, a[10000],n, min, j1, tep, k, f,max;
	scanf("%d", &t);
	for (i = 0; i < t; i++) {
		scanf("%d", &n);
		for (j = 0; j < n; j++) {
			scanf("%d", &a[j]);
		}
		for (j = 0; j < n - 1; j++) {
			min = a[j];
			f = 0;
			for (j1 = j+1; j1 < n; j1++) {
				if (a[j1] < min) {
					min = a[j1];
					k = j1;
					f = 1;
				}
			}
			if (f == 1) {
				tep = a[j];
				a[j] = a[k];
				a[k] = tep;
			}
		}

		max = a[n - 1];
		for (j = 1; j <= n; j++) {
			if (j * a[n - j] > max) {
				max = j * a[n - j];
			}
		}
		printf("%d\n", max);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 61