#P14619. [2019 KAIST RUN Fall] Maximizer
[2019 KAIST RUN Fall] Maximizer
题目描述
Maximizer has two permutations and . Both have length and consists of from to .
Maximizer wants to maximize the sum of differences of each element, . But he can only swap two adjacent elements in . Precisely, he can only swap and for some from to . He can swap as many times as he wants.
What is the minimum number of swaps required for maximizing the difference sum?
输入格式
The first line contains an integer . ()
The second line contains integers ().
The third line contains integers ().
Each of and is a permutation. In other words, it is consisted of distinct integers from to .
输出格式
Print an integer, the minimum number of swaps required for maximizing the difference sum.
3
1 2 3
1 2 3
2
4
3 4 1 2
3 2 4 1
3
京公网安备 11011102002149号