#abc302g. G - Sort from 1 to 4
G - Sort from 1 to 4
Score : points
问题描述
你得到一个长度为 的序列 ,其中包含 到 之间的整数。
Takahashi 可以执行以下操作任意次数(包括零次):
- 选择一对整数 ,满足 ,然后交换 和 。
找出使 变为非递减所需的最少操作次数。
若对于所有 ,均有 ,则称该序列为非递减序列。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length , consisting of integers between and .
Takahashi may perform the following operation any number of times (possibly zero):
- choose a pair of integer such that , and swap and .
Find the minimum number of operations required to make non-decreasing.
A sequence is said to be non-decreasing if and only if for all .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum number of operations required to make non-decreasing in a single line.
Sample Input 1
6
3 4 1 1 2 4
Sample Output 1
3
One can make non-decreasing with the following three operations:
- Choose to swap and , making .
- Choose to swap and , making .
- Choose to swap and , making .
This is the minimum number of operations because it is impossible to make non-decreasing with two or fewer operations.
Thus, should be printed.
Sample Input 2
4
2 3 4 1
Sample Output 2
3
update @ 2024/3/10 08:30:13