There is a permutation of \(1 ... N\). The first \(k\) numbers, \(p_1,p_2,...,p_k\), in the permutation have been determined.
Define a range \([l, r]\) in permutation \(p\) to be a range continuous segment if and only if:
$$max(p_l,p_{l+1},...,p_r) - min(p_l,p_{l+1},...,p_r) = r - l$$
Among all possible permutation \(p\), find the maximum number of range continuous segments in the permutation and output the permutation.
If there are multiple permutations that provide the maximum number of range continuous segments please choose any one of them.
Subtasks # | Score | Constraits |
---|---|---|
1 | 10 | \(n \leq 10\) |
2 | 20 | \(n \leq 22\) |
3 | 10 | \(k \leq 1\) |
4 | 20 | \(k = n\) |
5 | 40 | - |
The first line contains 2 integers \(n, k\), which represent the length of the permutaiton and the predetermined number of numbers.
The second line contains \(k\) space separated positive integers \(p_1,p_2,...,p_k\) representing the known part of the permutation.
The first line should contain a single integer representing the maximum number of range continuous segments. The second line should contain the permutation.
Sample Input 1 | Sample Output 1 |
4 1
|
8
|
Subtask | Score |
---|---|
1 | 10 |
2 | 20 |
3 | 10 |
4 | 20 |
5 | 40 |