MicrosoftOA #7
Sum of Final Prices (Next Lower-or-Equal)
估计中等可在线判题
考点(AI 标注)单调栈与堆
Each item's price is reduced by the price of the first item to its right whose price is not higher than its own; if there is no such item, it sells at its original price. Output the total selling price and the 0-based indices of the items sold at the original price, in ascending order.
输入格式
The first line contains n (1..100000), and the second line contains n prices (1..10⁸).
输出格式
On the first line output the total selling price. On the second line, first output the number of items sold at the original price, then output their indices in ascending order.
样例 1
输入:
6
2 3 1 2 4 2
输出:
8
2 2 5
样例 2
输入:
2
5 5
输出:
5
1 1
样例 3
输入:
3
1 2 3
输出:
6
3 0 1 2
样例说明
Example 1: the selling prices are 1, 2, 1, 0, 2, 2, summing to 8; indices 2 and 5 sell at the original price.
Example 2: the first item is fully offset by the second, leaving only the second at its original price 5, at index 1.
Example 3: every item to the right is more expensive, so all three sell at the original price, for a total of 6, at indices 0, 1, 2.