#P3696. Campus Idol Group Popularity Correction
Campus Idol Group Popularity Correction
Campus Idol Group Popularity Correction
In a Bushiroad party, there are N campus idol groups. Each group is associated with a school, and the school IDs range from 1 to N. Note that a school may have multiple groups performing or may have none at all. After all groups perform, two popularity ranking lists are generated: one at halftime and one at the end. Both lists are sorted in descending order of popularity. The halftime ranking is correct, and for each group the school ID is given. In the final ranking, however, the school IDs might have been recorded incorrectly. It is known that each group’s final popularity is at least as high as its halftime popularity. Since a group’s school cannot change, if we denote by (h_1, h_2, \ldots, h_k) the positions (1-indexed) at which a school appears in the halftime ranking and by (f_1, f_2, \ldots, f_k) the positions at which it appears in the final ranking (when arranged in increasing order), then the following condition must hold for each school and for each occurrence (i): [ f_i \leq h_i ] To fix the inconsistencies, you are allowed to change the school ID of some groups in the final ranking (the popularity values or the order in the final ranking remain unchanged). However, after the modifications, the multiset of school IDs in the final ranking must exactly match that of the halftime ranking (i.e. each school appears exactly as many times as it does in the halftime ranking) and the above condition must hold. Your task is to determine the minimum number of groups in the final ranking that must have their school ID modified so that these conditions are satisfied.
inputFormat
The input consists of three lines:
- The first line contains a single integer (N) ((1 \leq N \leq 10^5)) representing the total number of groups.
- The second line contains (N) space-separated integers representing the halftime ranking. The (i)-th integer is the school ID of the group at position (i) (positions are 1-indexed, with position 1 being the highest popularity).
- The third line contains (N) space-separated integers representing the final ranking (which might contain errors).
outputFormat
Output a single integer — the minimum number of modifications (i.e. the number of groups in the final ranking whose school IDs need to be changed) to make the final ranking consistent with the halftime ranking as per the conditions described.
sample
3
1 2 1
1 1 2
1