#P5967. K-th Necklace Query

    ID: 19192 Type: Default 1000ms 256MiB

K-th Necklace Query

K-th Necklace Query

There are n labeled beads. The value of the i-th bead is \(a_i\). You may select any subset of beads (possibly none) to form a necklace. The value of a necklace is defined as the sum of the values of the selected beads.

All possible necklaces are sorted in ascending order primarily by their value. If two necklaces have the same value, they are sorted by the lexicographical order of the set of bead labels (each set is considered as an increasing sequence of integers). Note that the empty necklace is considered valid and, by definition, is lexicographically smallest.

Given an integer \(k\), output the value of the \(k\)-th necklace in the sorted order, followed by the bead labels used (if any). All bead labels are 1-indexed.

inputFormat

The first line contains two integers \(n\) and \(k\), where \(n\) is the number of beads and \(k\) is the query index (1-indexed). The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\), representing the value of each bead.

outputFormat

Output the value of the \(k\)-th necklace followed by the labels of the beads (in increasing order) that form the necklace. If the necklace is empty, output only the value, which will be 0.

sample

3 4
1 2 3
3 1 2

</p>