Problem 571
Height Checker
Easy · 10 pts · Array, Sorting
Problem
Students stand in a line for a photo, and they are supposed to be ordered by height in non-decreasing order. You are given their current heights in line order. Count how many positions hold a student whose height differs from the height that should be at that position in the correctly sorted line. Sort a copy of the heights and compare it with the original position by position.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].
Output
Print the number of positions that do not match.
Constraints
1 <= N <= 100000; 1 <= A[i] <= 100
Example input
6 1 1 4 2 1 3
Example output
3
Explanation
The line 1 1 4 2 1 3 sorted is 1 1 1 2 3 4. Positions 2, 4 and 5 hold 4, 1 and 3 instead of 1, 3 and 4, so 3 positions differ.