Editorial for CCC '15 S3 - Gates
Submitting an official solution before solving the problem yourself is a bannable offence.
A simple greedy algorithm goes like this:
For each plane, assign it to the gate with the largest number that isn't occupied.
It's not hard to see why this is correct — indeed, intuitively, we're using the "worst" gate we can for each plane (since a gate with a lower number can serve at least every plane a gate with a higher number can).
Implementing this naïvely will result in a complexity of , which is enough for the weak data used on the actual CCC. To speed this up, we can use a balanced binary search tree to store free gates. In C++, this is the
set data structure, with a final time complexity of .