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
Somehow my solution passed batch 1 fine, except for an IndexError on test case 4. Has anyone else encountered this issue?
make sure to check if your planes gate list is empty (if it is then do not continue to pop)
sick birthday present
hi can someone give me a hint to how to implement an equivalent of the std::bitset's _find_next() function in python?
You should implement a solution with the correct complexity instead. Bitset is not the best way to approach this problem.
For Batch #11 Case #3, I got a TLE; however, on the official CCC grader, my submitted code gets full marks since the time limit is 5 seconds. So are the problems here supposed to be mirror's of the one's found on other websites? Or could there be minor differences like time limit?
In the second set of cases they augmented the test data to eliminate weaker solutions (That can still pass on the CCC). You have to find a more efficient solution to pass the second set of cases, try looking at the data structure set.
What kind of person gets an airport as their birthday...
I think my solution is broken, but it still passes. Using this test case
my solution outputs 4, even though it should be 5. Did I misunderstand something, or has my solution miraculously passed despite being wrong?
Thanks in advance!
Edit: just solved the problem the right way, the solution I am referring to above can be found at https://dmoj.ca/submission/3196239
Can anyone tell me why std::lower_bound TLEs, but set::lower_bound ACs? I thought they both ran in
set::lower_bound
is a specialized lower_bound method forstd::set
that runs in time.std::lower_bound
only has this guarantee for random access iterators, whichstd::set
does not have. For non-random access iterators such as withstd::set
, it takes time on average (based on https://cplusplus.com/reference/algorithm/lower_bound/).La-da-da-da-dah You know I'm mobbin' with the T.L.E.
make this a real remix of the song
Even the algorithm worked as long as you code it in C
This comment is hidden due to too much negative feedback. Show it anyway.
I still passed lol.
Implementing a TreeSet will hold back your worries about TLE.
How come my 15/30 submission did not get TLE.
Is it advised not to use ArrayList as it is slower than a regular array to optimize the speed of the program? Is the difference between an array and an ArrayList not large enough to slow down the program so drastically that the time limit would not be exceeded? If not, then it must be the algorithm that is at fault then, correct? And if so, any tips on how to optimize my algorithm?
Your algorithm is wrong, one possible approach is to use binary search and a set to reduce the time complexity to .
Not sure what the set equivalent is in Java though.
TIL that .
The original CEMC test data is now a 50% subtask (5 points). New cases, worth the other 50%, are added to award to the truly correct solutions.
All submissions have been rejudged.
Note: For of the CEMC cases, and . Those cases are worth of the total points.