Canadian Computing Competition: 2015 Stage 1, Senior #3
For your birthday, you were given an airport.
The airport has gates, numbered from
to
.
planes arrive at the airport, one after another. You are to assign the
plane to permanently dock at any gate
(
), at which no previous plane has docked. As soon as a plane cannot dock at any gate, the airport is shut down and no future planes are allowed to arrive.
In order to keep the person who gave you the airport happy, you would like to maximize the number of planes starting from the beginning that can all dock at different gates.
Input Specification
The first line of input contains (
), the number of gates at the airport.
The second line of input contains (
), the number of planes which will land.
The next lines contain one integer
, (
), such that the
plane must dock at some gate from
to
, inclusive.
Note that for at least 3 marks for this question, and
.
Output Specification
Output the maximum number of planes that can land starting from the beginning.
Sample Input 1
4
3
4
1
1
Output for Sample Input 1
2
Explanation of Output for Sample Input 1
The first plane can go anywhere, but it is best to not put it into Gate . Notice that planes
and
both want to dock into Gate
, so plane
is unable to dock.
Sample Input 2
4
6
2
2
3
3
4
4
Output for Sample Input 2
3
Explanation of Output for Sample Input 2
The first two planes will dock in gates and
(in any order). The third plane must dock at Gate
. Thus, the fourth plane cannot dock anywhere, and the airport is closed, even though plane
would have been able to dock.
Comments