#P5967. [POI 2016] Korale

[POI 2016] Korale

Problem Description

There are nn labeled beads. The value of the ii-th bead is aia_i.

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 kk-th smallest necklace and the set of bead labels used.

Input Format

The first line contains two positive integers n,kn,k. The second line contains nn positive integers, where the ii-th number is the value aia_i of the ii-th bead.

Output Format

Output the value of the kk-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 100%100\% of the testdata, 1n1061\le n\le 10^6, 1kmin(2n,106)1\le k\le \min(2^n,10^6), 1ai1091\le a_i\le 10^9.

Translated by ChatGPT 5