MicrosoftOA #24
Find Minimum Cost
估计中等评测数据准备中,可先阅读题面
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 priceX. - Type 2: A solar panel which provides
2 * A[k]amount of power for priceY. 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 fromYis 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.