#P15109. Adverse Present
Adverse Present
Problem Description
You are given a permutation of length , and an integer .
One operation is defined as follows:
Choose a subsequence, delete it from the original sequence, and append it to the end of the permutation in the original order.
Please output the minimum number of operations needed to sort this permutation in increasing order, and also construct a sequence of operations. In particular, if or , you do not need to construct it (see the input and output formats).
Definition of a permutation: a permutation of length is a sequence consisting of positive integers from to , where each number appears exactly once.
Definition of a subsequence: we say that sequence is a subsequence of sequence if and only if can be obtained by deleting some elements from .
Input Format
The first line contains two integers , representing the permutation length, and whether you need to construct a solution.
The second line contains numbers. The -th number is the -th element of the permutation . It is guaranteed that all these numbers are pairwise distinct.
Output Format
The first line contains one number , representing the minimum number of operations needed.
If or , output -1 on the second line and exit.
Otherwise, output the next lines. In each line, the first number is the length of the subsequence chosen in this operation. Then output pairwise distinct numbers, indicating which indices (in the current sequence) are chosen to form the subsequence. The order of these indices can be arbitrary.
4 1
4 3 2 1
2
2 1 3
2 1 3
5 1
5 2 3 4 1
2
3 2 3 4
1 1
5 0
5 2 3 4 1
2
-1
8 0
1 8 5 4 3 2 6 7
3
-1
8 0
1 3 5 7 2 4 6 8
2
-1
Hint
This problem uses bundled testdata.
.
.
.
.
.
no special constraints.
For all data, , and it is guaranteed that is a permutation.
Translated by ChatGPT 5