cswork / OA打开练习工作台

AmazonOA #41

Maximize Total Memory Points

估计简单可在线判题

考点(AI 标注)贪心调度原地数组

Read all chapters in any order; after reading each chapter, you score the sum of the memory values of all chapters read so far. Find the maximum possible sum of all these scores. Memory values may be negative.

输入格式

The first line contains n (1..100000), and the second line contains n memory values (−1000..1000).

输出格式

Output a single integer answer.

样例 1

输入:

3
3 4 5

输出:

26

样例 2

输入:

2
-2 -1

输出:

-4

样例 3

输入:

1
0

输出:

0

样例说明

Example 1: reading in the order 5, 4, 3 gives scores 5, 9, 12, for a total of 26. Example 2: reading −1 first and then −2 gives scores −1, −3, for a total of −4, which is larger than the −5 of the other order. Example 3: the total is 0.