#P5967. [POI 2016] Korale
[POI 2016] Korale
Problem Description
There are labeled beads. The value of the -th bead is .
Now you may choose some beads to form a necklace (you may also choose none). The value of a necklace is the sum of the values of all beads in it.
Consider all possible necklaces and sort them: first by total value in increasing order; if the total values are the same, sort by the lexicographical order of the set of used bead labels in increasing order.
Output the value of the -th smallest necklace and the set of bead labels used.
Input Format
The first line contains two positive integers . The second line contains positive integers, where the -th number is the value of the -th bead.
Output Format
Output the value of the -th smallest necklace on the first line. On the second line, output the labels of all beads in this necklace in increasing order.
4 10
3 7 4 3
10
1 3 4
Hint
Constraints: for of the testdata, , , .
Translated by ChatGPT 5