AtCoder Regular Contest 124
翻译中…
Problem Statement
翻译中…
Given is a sequence $p$ of length $N+M$, which is a permutation of $(1,2 \ldots, N+M)$. The $i$-th term of $p$ is $p_i$.
翻译中…
You can do the following Operation any number of times.
翻译中…
Operation: Choose an integer $n$ between $1$ and $N$ (inclusive), and an integer $m$ between $1$ and $M$ (inclusive). Then, swap $p_{n}$ and $p_{N+m}$.
翻译中…
Find the minimum number of Operations needed to sort $p$ in ascending order. We can prove that it is possible to sort $p$ in ascending order under the Constraints of this problem.
翻译中…
Constraints
翻译中…
- All values in input are integers.
$1 \leq N,M \leq 10^5$$1 \leq p_i \leq N+M$$p$is a permutation of$(1,2 \ldots, N+M)$.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N M
p_{1} \cdots p_{N+M}
翻译中…
Output
翻译中…
Print the minimum number of Operations needed to sort $p$ in ascending order.
翻译中…
样例
Input #1
2 3
1 4 2 5 3
Output #1
3
Input #2
5 7
9 7 12 6 1 11 2 10 3 8 4 5
Output #2
10
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。