[伯俊]217ロープ(銀4)


白駿(シルバー4)-2217.ロープ(銀4)

に答える

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Integer[] rope = new Integer[n];
		
		for(int i=0; i<n; i++) {
			rope[i] = sc.nextInt();
		}
		Arrays.sort(rope,Collections.reverseOrder());
		
		int max = rope[0];
		
		for(int i=1; i<n; i++) {
			rope[i] *= (i+1);
			if(max <rope[i]) max = rope[i];
		}
		System.out.println(max);
	}
}