#C6938. Minimum Operations to Sort Post-it Notes
Minimum Operations to Sort Post-it Notes
Minimum Operations to Sort Post-it Notes
You are given N post-it notes, each with a distinct priority from 1 to N. The notes are arranged in a random order. In one operation, you can take a note and reposition it so that eventually, the notes are in increasing order of their priorities.
The goal is to compute the minimum number of operations required to achieve this sorted order. If you can identify a subsequence of notes that are already in the correct relative order, then you only need to move the rest. Formally, let L be the length of the longest contiguous subsequence of notes which, when mapped to their natural order positions, are in increasing order. Then the minimum number of operations required is given by:
\( N - L \)
where N is the total number of notes.
inputFormat
The first line of the input contains a single integer N representing the number of post-it notes.
The second line contains N space-separated integers representing the priorities of the post-it notes.
outputFormat
Output a single integer representing the minimum number of operations required to sort the post-it notes in increasing order.
## sample5
2 4 1 3 5
3
</p>