cswork / OA打开练习工作台

MicrosoftOA #24

Find Minimum Cost

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

考点(AI 标注)背包计数贪心调度

You are given a list of houses, such that A[k] corresponds to the amount of energy needed for house k. You will be installing two types of solar panels:

  • Type 1: A solar panel which provides A[k] amount of power for price X.
  • Type 2: A solar panel which provides 2 * A[k] amount of power for price Y. Your goal is to find the minimum cost such that all houses are provided with at least their required amount of power. Note: The power distributed from Y is not sequential, as you only focus on providing at least the net amount of energy of all the houses.

Example 1

Input:

A = [4, 3, 5, 2]
X = 2
Y = 5

Output:

7

Explanation: Assign solar panel type Y to A[2], which will cover A[1] and A[3], and then assign solar panel type X to A[0]. Thus the minimum cost is 5 + 2 = 7.