第五回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 180)
翻译中…
Problem Statement
翻译中…
You are given a permutation $P=(P_1,P_2,\cdots,P_N)$ of $(1,2,\cdots,N)$. Additionally, you are given an integer $K$.
翻译中…
You can perform the following operation zero or more times:
翻译中…
- Choose integers
$l$and$r$($1 \leq l < r \leq N$). Here, the pair$(l,r)$must satisfy all of the following conditions: $K \leq r-l$.$P_l > P_r$at the time of the operation.- The pair
$(l,r)$has never been chosen before.
- Then, swap the values of
$P_l$and$P_r$.
翻译中…
You want to maximize the number of operations. Find one way to achieve this.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 500$$1 \leq K \leq N-1$$(P_1,P_2,\cdots,P_N)$is a permutation of$(1,2,\cdots,N)$.- All input values are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N K
P_1 P_2 \cdots P_N
翻译中…
Output
翻译中…
Print the answer in the following format:
翻译中…
m
l_1 r_1
l_2 r_2
\vdots
l_m r_m
翻译中…
Here, $m$ is the maximum number of operations, and $l_i$ and $r_i$ are the values of $l$ and $r$ chosen in the $i$-th operation, respectively. If multiple solutions exist, you can print any of them.
翻译中…
样例
Input #1
3 1
3 2 1
Output #1
3
2 3
1 3
1 2
In this example, the maximum number of operations is $3$. The operations in the sample output proceed as follows:
- 1st operation: Choose $(l,r)=(2,3)$. We have $1 \leq 3-2$ and $P_2 > P_3$, and $(2,3)$ has not been chosen before, so the conditions are satisfied. Swap $P_2$ and $P_3$, resulting in $P=(3,1,2)$.
- 2nd operation: Choose $(l,r)=(1,3)$. We have $1 \leq 3-1$ and $P_1 > P_3$, and $(1,3)$ has not been chosen before, so the conditions are satisfied. Swap $P_1$ and $P_3$, resulting in $P=(2,1,3)$.
- 3rd operation: Choose $(l,r)=(1,2)$. We have $1 \leq 2-1$ and $P_1 > P_2$, and $(1,2)$ has not been chosen before, so the conditions are satisfied. Swap $P_1$ and $P_2$, resulting in $P=(1,2,3)$.
Input #2
5 4
1 4 3 2 5
Output #2
0
Input #3
4 2
4 1 2 3
Output #3
2
1 4
1 3
Input #4
10 5
8 7 6 10 9 3 1 5 2 4
Output #4
15
3 8
2 8
3 10
3 9
1 8
2 10
2 9
2 7
1 10
5 10
1 9
4 10
4 9
1 7
1 6
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。