Simulate a single-lane bus stop where each bus parks in the frontmost free spot, waits if a bus ahead is still parked, and departs after its dwell time; report the parking spot of the m-th bus.
Medium5SimulationQueueImplementationInterviewNo attempts yetTime limit1sMemory limit512 MBYoungwoo commutes by bus from Suwon to Seoul every day. His bus is so crowded that arriving a little late can mean being pushed aside and left behind, and the interval between buses is so long that missing one means being late for class. So today he wants to compute in advance where his bus will stop and wait at that spot.
The bus stop is a straight single-lane passage. Spots are numbered 1, 2, ..., n from the front in the direction of travel, and at most n buses can be parked at the same time. The stop display shows each bus arrival time in minutes and dwell time in minutes for passenger boarding. To prevent congestion inside the stop, buses enter and leave under the following rules.
Dwell time is counted from the moment a bus actually parks. Time spent waiting outside the entrance does not count toward it.
The first line gives n, the number of buses that can park at the same time, and m, the number of buses up to and including the bus Youngwoo wants to ride (1≤n≤10, 1≤m≤100).
Each of the next m lines gives the arrival time t and the dwell time p of one bus, in arrival order. Buses arriving at the same minute are treated as arriving in input order (1≤t≤100, 1≤p≤10, ti≤ti+1).
Print, on one line, the spot number where the bus Youngwoo wants to ride (that is, the m-th bus) parks.