cswork / OA打开练习工作台

JPMorgan ChaseOA #28

Maximum Amount

估计中等可在线判题

考点(AI 标注)二分查找贪心调度单调栈与堆

Each customer buys exactly one item; the price of a product for that sale equals its remaining stock before the sale, and the stock drops by one afterward. Given m customers, find the maximum revenue, without taking any modulo. The original does not guarantee enough stock, so this site specifies that the output is −1 when the total stock is <m. The explanation of original example 1 misstates the stock; with input [10,10,8,9,1] and m=6, the answer should be 55.

输入格式

The first line contains n m, followed by n values of quantity; full original bounds 1≤n≤100000, 1≤m≤1000000000, 1≤quantity[i]≤1000000000. m≤total stock is not required.

输出格式

Output a single integer answer.

样例 1

输入:

5 6
10 10 8 9 1

输出:

55

样例 2

输入:

3 4
1 2 4

输出:

11

样例 3

输入:

2 3
1 1

输出:

-1

样例说明

The outputs of the three public examples are, in order: 55; 11; -1. These answers have been checked by independent enumeration or direct simulation.