Codeforces 730G. Car Repair Shop 【map】
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1
The i-th request is characterized by two values: si — the day when a client wants to start the repair of his car, di— duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.
Polycarp is making schedule by processing requests in the order from the first to the n
- If the car repair shop is idle for di days starting from si (si, si + 1, ..., si + di - 1), then these days are used to repair a car of the i-th client.
-
Otherwise, Polycarp finds the first day x (from 1 and further) that there are di subsequent
days when no repair is scheduled starting from x
Given n requests, you are asked to help Polycarp schedule all of them according to the rules above.