View Code of Problem 61

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            int[] nums = new int[n];
            for (int j = 0; j < nums.length; j++) {
                nums[j] = scanner.nextInt();
            }
            Arrays.sort(nums);
            int res = 0;
            for (int j = 0; j < nums.length; j++) {
                if (nums[j]*(nums.length-j) > res){
                    res = nums[j]*(nums.length-j);
                }
            }
            System.out.println(res);
        }
    }
}

Double click to view unformatted code.


Back to problem 61