View Code of Problem 61

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int i = 0; i < t; i ++) {
			int num = sc.nextInt();
			int[] arr = new int[num];
			for(int j = 0; j < num; j ++) {
				arr[j] = sc.nextInt();
			}
			Arrays.sort(arr);
			int max=arr[0];
	        for(int j = 0;j < num; j++){
	            if(arr[j] * (num - j) > max)
	            	max = arr[j] * (num - j);
	        }
	        System.out.println(max);
			
		}
	}

}

Double click to view unformatted code.


Back to problem 61