Bob Sort

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Given a sequence A with n integers, a_1, a_2, \ldots, a_n, Bob wants to sort the sequence in non-descending order by using the following operation a number of times.

  • Bob will choose some different indices (say k), i_1, i_2, \ldots, i_k, and move a_{i_1} to the position of i_2, move a_{i_2} to the position of i_3, \ldots, and finally move a_{i_k} to the position of i_1. For example, if n=4 and A = [1, 2, 3, 4], Bob chooses 3 indices i_1 = 3, i_2 = 1, i_3 = 4, then the sequence A after the operation is [3, 2, 4, 1].
  • The cost of one operation is 1.

Bob wants to sort the sequence in non-descending order at the minimal cost. Also, Bob is busy. So the total number of selected indices is no more than m, i.e. \sum{k} \le m. Can you help Bob find a way to sort the sequence? If it's impossible, output -1.

Input Specification

The first line of input contains two integers n and m (1 \le n \le 2\times 10^5, 0 \le m \le 2 \times 10^5).

The second line of input contains n integers a_i (1 \le a_i \le 10^9).

Output Specification

If it's impossible to sort the sequence in non-descending order, output -1 in one line. If it's possible, output one integer q in the first line, indicating the cost to sort the given sequence. Each of the following q sections contains two lines. The first line contains one integer k, the number of indices selected. The second line contains k different integers, i_1, i_2, \ldots, i_k. If there are multiple solutions, output any one.

Note that the checker for this problem is custom and, hence, the whitespace is strict, so do not output excess whitespace.

Constraints

Subtask Points Additional constraints
1 0 Sample cases.
2 5 n, m \le 2.
3 5 n \le 5.
4 5 1 \le a_i \le 2.
5 10 Sequence A is a permutation of 1 to n and m = 2 \times n.
6 10 Sequence A is a permutation of 1 to n and n \le 1000.
7 15 Sequence A is a permutation of 1 to n.
8 15 m = 2 \times n.
9 15  n \le 1000.
10 20 No additional constraints.

Sample Input 1

5 5
3 2 3 1 1

Sample Output 1

1
5
1 4 2 3 5

Sample Input 2

6 9
6 5 4 3 2 1

Sample Output 2

2
6
1 6 2 5 3 4
3
3 2 1

Sample Input 3

4 3
2 1 4 3

Sample Output 3

-1

Sample Input 4

2 0
2 2

Sample Output 4

0

Sample Input 5

6 8
6 5 4 3 2 1

Sample Output 5

3
2
3 4
4
1 6 2 5
2
2 1

Comments

There are no comments at the moment.