← 返回 amazon 的题目列表Maximum Score from Sequential Cumulative Array Selection
类型:online_judge
amazon
Given an array, you can choose a number in any order, and each time the score obtained is the sum of the currently chosen number and the previous total sum. Calculate the maximum score obtainable. Suppose you have the following array: [5, 3, 2, 8].
Problem: What is the maximum score?
The elements in the array can be any integer.
Input Format
An integer array arr.
Output Format
Return an integer representing the maximum score that can be obtained.
Sample Input
Input: arr = [5, 3, 2, 8]
Output: 43
Constraints
The length of the array is no more than 1000.
Each integer's absolute value is no more than 1000.
Example
Input
[5, 3, 2, 8]