View Code of Problem 61


import java.util.Arrays;
import java.util.Collections;
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 a[]=new int[n];
			for(int j=0;j<n;j++) {
				a[j]=scanner.nextInt();
			}
			Arrays.sort(a);
			int count=1;
			int max=a[n-1];
			for(int k=n-2;k>=0;k--) {
				count++;
				if (a[k]*count>max) {
					max=a[k]*count;
				}
			}
			System.out.println(max);
		}
		
		scanner.close();
	
	}
}

Double click to view unformatted code.


Back to problem 61