Matches
InterviewTime limit2sMemory limit512 MB
Assign N participants to rooms 1..N so that the number of participants whose passport number equals their room number is maximized.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Hash map, Two pointers
- Solved
- No attempts yet
Problem
The participants of the ICPC (Intergalactic Collegiate Programming Contest) have been lodged in a newly built hotel. The hotel has single rooms, numbered with the integers from 1 to with no gaps. Each participant has a known passport number, an integer from 1 to inclusive. Participants from different planets may have the same passport number.
While waiting to be checked in, several participants noticed that a funny situation is possible: a passport number may coincide with a room number. They then asked themselves the following question. What is the largest number of such coincidences that would be possible if the participants were deliberately assigned to rooms so as to maximize that number?
Given the number of rooms in the hotel and the list of participants' passport numbers, find the answer to this question.
Input
The first line of the input contains a single integer (). The -th of the following lines contains an integer , the passport number of the -th participant ().
Output
Print a single integer: the largest number of coincidences between passport numbers and room numbers that can be obtained when the participants are assigned to rooms.