atcoder#ARC114F. [ARC114F] Permutation Division
[ARC114F] Permutation Division
Score : points
Problem Statement
You are given a permutation of .
You can divide into exactly non-empty contiguous subsequences as you like.
Maroon will rearrange those subsequences you make and concatenate them to make a new permutation . Here, he will lexicographically maximize .
You want to divide in a way that lexicographically minimizes . Find in that case.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print when you optimally divide .
3 2
1 2 3
2 3 1
You have two ways to divide : and .
In the former case, Maroon will rearrange them in the order to get .
In the latter case, Maroon will rearrange them in the order to get .
Thus, you should choose the latter.
4 3
4 3 1 2
4 3 1 2
20 7
10 5 8 2 1 9 12 20 15 3 7 6 19 4 11 17 13 14 16 18
10 5 8 2 7 6 19 4 11 17 13 14 16 18 3 1 9 12 20 15