Problem link
The order of discarding is given, so we can simulate the process of discarding.
In each time, we can calculate the page that contains the first special item that has not been discarded, and then locate all the special items that need to be discarded at one time. Repeat this process until all special items are discarded.
Each time at least one item would be discarded, so the time complexity is O(m).
A solution in c++
0 Comments
If you have any doubts, Please let me know