#P17010. [GESP202606 五级] 排排坐

    ID: 19300 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>数学贪心排序前缀和2026GESP

[GESP202606 五级] 排排坐

Problem Description

The teacher is giving candies to children.

Each child first writes a number on their hand, then sits in a row.

The rule for giving candies is: each child gets a number of candies equal to the sum of the numbers on their own hand and on the hands of all children to their left.

Now all children have already written their numbers.

Please help the children arrange a suitable seating order so that the total number of candies they receive is as large as possible, and output this maximum value.

Input Format

The input has 22 lines.

The first line contains a positive integer nn, representing the number of children.

The second line contains nn positive integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n, representing the numbers on the children’s hands. The integers are separated by spaces.

Output Format

Output one integer, representing the maximum total number of candies the children can receive.

5
7 5 8 9 3
111

Hint

Sample Explanation

After arranging the seats, from left to right the numbers on the children’s hands are: 9,8,7,5,39, 8, 7, 5, 3.

Then the maximum number of candies can be obtained: $(9) + (9 + 8) + (9 + 8 + 7) + (9 + 8 + 7 + 5) + (9 + 8 + 7 + 5 + 3) = 111$.

Constraints

1≤n≤10001 \le n \le 1000,1≤ai≤10001 \le a_i \le 1000。

Translated by ChatGPT 5