LCC '25 Contest 3 J4 - Icicles
View as PDFOn the way home, a very childish Eric passes under a low-hanging roof of a shop, and sees a line of icicles hanging down, each with a distinct length
. He wants to take the longest icicles with him, but he knows icicles are fragile. If he takes the
icicle from the left, all icicles to the right fall down and crack into pieces. His hand can only carry at most
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
Subtask 1 [30%]
Subtask 2 [70%]
No further constraints.
Input Specification
The first line will contain space-separated integers .
The next line will contain distinct space separated integers
.
Output Specification
On the first line, output a single integer, the maximum sum.
On the second line, output 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