Under construction

Still being built. Things may change

Necklaces

Time limit2sMemory limit1024 MB

Summary
Given n beads with values, find the k-th subset ordered by total value, with ties broken by the lexicographic order of bead numbers.
Level

Hard8 of 10

Topics
Sorting, Binary search, Dynamic programming
Solved
No attempts yet

Statement

Bajtyna has nn beads numbered from 1 to nn. All beads are distinct. Each bead has a value in bajtalars.

Bajtyna wants to make a necklace from some of her beads. There are many ways to do this. Two ways are different if the sets of beads they use are different. Bajtyna wants to sort all the ways using these rules:

  1. A way with a smaller total value comes earlier.
  2. If two ways have the same total value, compare the sorted lists of bead numbers they use in lexicographic order.∗

For example, suppose there are four beads with values 3, 7, 4, and 3, in order. Then a necklace can be made in 16 ways. The table below shows these ways in Bajtyna's order.

WayValues of chosen beadsTotal valueBead numbers
1none0none
2331
3334
4443
53 361 4
63 471 3
7772
84 373 4
93 7101 2
103 4 3101 3 4
117 3102 4
127 4112 3
133 7 3131 2 4
143 7 4141 2 3
157 4 3142 3 4
163 7 4 3171 2 3 4

Bajtyna wants the necklace that is in position kk in this order. Find it.

∗ Sequence i1,...,ipi_1, ..., i_p is smaller than j1,...,jqj_1, ..., j_q if either the first sequence is a prefix of the second one (so p<qp < q and i1=j1,...,ip=jpi_1 = j_1, ..., i_p = j_p), or at the first position uu where they differ, iu<jui_u < j_u (with i1=j1,...,iu−1=ju−1i_1 = j_1, ..., i_{u-1} = j_{u-1}).

Input

The first line contains two positive integers nn and kk, separated by a single space. Here nn is the number of beads, and kk is the position of the wanted way in the order described above.

The second line contains nn positive integers a1,a2,...,ana_1, a_2, ..., a_n, separated by single spaces. Here aia_i is the value of bead ii.

You may assume that Bajtyna did not make a mistake, so there are at least kk different ways to make her necklace.

Output

Print one integer on the first line: the total value of the beads in the necklace you found.

Print the bead numbers used in the necklace on the second line, in increasing order, separated by single spaces.

Constraints

  • n,k≤106n, k \le 10^6
  • ai≤109a_i \le 10^9

Examples1

  1. Example 1

    Input
    4 10
    3 7 4 3
    
    Expected output
    10
    1 3 4