Airport
InterviewTime limit1sMemory limit256 MB
Each arriving plane takes the largest free gate up to its limit gi, and the count stops at the first plane with no free gate.
- Level
Medium4 of 10
- Topics
- Union-find, Greedy
- Solved
- No attempts yet
Problem
An airport has gates, numbered through .
planes arrive in a fixed order. Plane docks permanently at one gate that is still empty among gates through . A gate holds at most one plane, and a plane that has docked never moves to another gate. If no gate is left for the plane that is arriving, the airport closes and no further plane arrives.
Dock as many planes as possible. How many planes dock at most?
Input
The first line contains the number of gates ().
The second line contains the number of planes ().
Each of the next lines contains one integer (), the highest gate number that plane can use, given in arrival order.
Output
Print the maximum number of planes that can dock, on one line.