AmazonOA #356
VM Rental Revenue
估计中等可在线判题
Each time, first charge the sum of the current maximum stock and the current minimum non-zero stock, then rent out one unit from any type with the maximum stock. Zero stock is not considered for the minimum, and ties for the maximum can be broken arbitrarily. Compute the total income over all requests.
输入格式
The first line contains n m and the second line contains n stock values. OCR313 gives n≤10^6, while 314 gives 10^5 with stock≤10^6. This site covers the broader sourced domain: 1≤n≤10^6, 0≤stock[i]≤10^6, 0≤m≤sum(stock)≤10^12, without imposing sum>m.
输出格式
Output a single integer, the answer.
样例 1
输入:
3 4
1 2 4
输出:
15
样例 2
输入:
4 4
2 1 1 3
输出:
12
样例 3
输入:
3 3
10 10 11
输出:
60
样例说明
The examples give 15, 12 and 60. The 1+4=6 in the OCR313 table is an arithmetic typo and should be 5; the 5 VM types in 316 do not match the three-item input and should be 3 types.