#C3126. Maximum Diagonal Sum

    ID: 46519 Type: Default 1000ms 256MiB

Maximum Diagonal Sum

Maximum Diagonal Sum

Given an integer \(n\) and a list of integers representing the values in an \(n\)-dimensional grid, you are allowed to perform any number of swaps within the grid. Since swaps are allowed, you can place any \(n\) numbers onto the diagonal of the grid. The task is to compute the maximum possible sum of the diagonal.

The diagonal is defined as the collection of \(n\) elements where each element is chosen from the list, and their total sum is maximized. In effect, you should select the \(n\) largest integers from the list.

For instance, if \(n=3\) and the grid values are from 1 to 27, the optimal diagonal sum is \(27+26+25=78\).

inputFormat

The first line contains a single integer \(n\) representing the number of diagonal elements.

The second line contains a space-separated list of integers representing the grid values.

outputFormat

Output a single integer: the maximum sum of the \(n\) largest numbers from the given list.

## sample
3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
78

</p>