LCC '25 Contest 3 J4 - Icicles

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Python 2.5s
Memory limit: 256M

Author:
Problem type

On the way home, a very childish Eric passes under a low-hanging roof of a shop, and sees a line of N icicles hanging down, each with a distinct length L_i. He wants to take the longest icicles with him, but he knows icicles are fragile. If he takes the i^\text{th} icicle from the left, all icicles to the right fall down and crack into pieces. His hand can only carry at most T icicles, though. What is the maximum total sum of the lengths of the icicles he can take with him, and what is the order in which he should take the icicles?

Subtasks

1 \leq T \leq N \leq 10^6

1 \leq L_i \leq 10^6

Subtask 1 [30%]

1 \leq T \leq N \leq 10^3

Subtask 2 [70%]

No further constraints.

Input Specification

The first line will contain space-separated integers N,T.

The next line will contain N distinct space separated integers L_i.

Output Specification

On the first line, output a single integer, the maximum sum.

On the second line, output T space-separated integers, the order of the indices of the icicles Eric should take.

Sample Input

5 2
3 4 8 6 5

Sample Output

14
4 3

Explanation for Sample Output

It is most optimal to take icicles of length 6 and 8. Make sure not to take the icicle of length 8 first, because then the icicle of length 6 will fall!


Comments

There are no comments at the moment.