cswork / OA打开练习工作台

AmazonOA #272

Maximize Sum of Array

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)贪心调度单调栈与堆

You are given an array of integers. Your task is to maximi

Example 1

Input:

arr = [4, 4, 8, 5, 3, 2]

Output:

17

Explanation: Steps:

  • Choose 5 from [4, 4, 8, 5, 3, 2]
  • Remove 4 and 2
  • Total sum = 5
  • Choose 4 from [4, 8, 5, 3]
  • Remove 4 and 3
  • Total sum = 5 + 4 = 9
  • Choose 8 from [8, 5]
  • Remove 8 and 5
  • Total sum = 9 + 8 = 17