#C9005. Minimum Students Movement
Minimum Students Movement
Minimum Students Movement
You are given a queue of n students with their heights. The students are standing in a line, and your task is to rearrange the queue so that the students appear in non-decreasing order of heights. However, you want to minimize the number of moves. A move consists of relocating a student to a different position.
This problem can be solved by finding the length of the longest subsequence that is already in non-decreasing order. Let \(L\) be this length and \(n\) be the total number of students. The minimum number of moves required is given by:
[ \text{moves} = n - L ]
Help determine the minimum number of students that need to be moved to achieve the desired ordering.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer \(n\) denoting the number of students.
- The second line (if \(n > 0\)) contains \(n\) space-separated integers representing the heights of the students.
outputFormat
Output a single integer to stdout — the minimum number of students that need to be moved to arrange the queue in non-decreasing order of heights.
## sample5
5 1 2 3 4
1
</p>