cswork / OAOpen practice workspace

MicrosoftOA #7

Sum of Final Prices (Next Lower-or-Equal)

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & Heaps

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.

Input

The first line contains n (1..100000), and the second line contains n prices (1..10⁸).

Output

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.

Example 1

Input:

6
2 3 1 2 4 2

Output:

8
2 2 5

Example 2

Input:

2
5 5

Output:

5
1 1

Example 3

Input:

3
1 2 3

Output:

6
3 0 1 2

Example notes

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.

Editorial

Loading solution…