#P5426. [USACO19OPEN] Balancing Inversions G
[USACO19OPEN] Balancing Inversions G
Problem Description
Bessie and Elsie are playing a game on a boolean array of length (). Bessie's score is the number of inversions in the first half of , and Elsie's score is the number of inversions in the second half of . An inversion is a pair of elements satisfying and , where . For example, an array with a block of 's followed by a block of 's has no inversions, while an array with 's followed by 's has inversions.
Farmer John happens to see this board, and he wonders what the minimum number of adjacent swaps is to make the game appear tied. Please help Farmer John compute the answer.
Input Format
The first line contains . The second line contains integers, each being or .
Output Format
Output the minimum number of moves needed to make the game tied.
5
0 0 0 1 0 1 0 0 0 1
1
Hint
In this example, initially the first half has inversion and the second half has inversions. After swapping the -th and the -th numbers, both subarrays have inversions.
Translated by ChatGPT 5