1439. Does Everyone Fit
A vehicle with cap seats drives from position 0 forwards, never turning
back. n bookings each say how many passengers board at one position and leave
at another.
Print YES if the vehicle is never over capacity, and NO otherwise.
Passengers leaving at a position are off before anyone boards there, so a booking ending exactly where another begins does not conflict.
There is no need to sort the bookings. Record the change at each position, at boarding and leaving, then sweep positions in order accumulating the running total. That total is the occupancy, and the answer is whether it ever exceeds the capacity.
Constraints - `1 ≤ n ≤ 100000` - `1 ≤ cap ≤ 1000000` - `1 ≤ passengers ≤ 1000` - `0 ≤ from < to ≤ 1000`
Input
The first line contains two integers n and cap.
Each of the next n lines contains three integers: the number of passengers, the boarding position, and the leaving position.
Output
Print YES if the vehicle never exceeds its capacity, otherwise NO.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.