A shuttle drives along a straight route and has a fixed seat capacity C. There are n trips; trip i boards p passengers at milepost s and drops them at milepost e (with s < e), so those passengers occupy seats over the half-open range [s, e). Because a passenger leaving at milepost e frees the seat exactly at e, a trip ending at e and another starting at e do not overlap. Determine whether the number of onboard passengers stays at or below C at every point of the route.
Line 1: two integers n and C.
Next n lines: three integers p, s, e describing one trip (1 ≤ p, 0 ≤ s < e).
Print YES if the capacity is never exceeded, otherwise NO.
Example 1
Input
2 3 2 1 5 2 3 7
Expected
NO
Explanation
On [3,5) both trips are aboard: 2 + 2 = 4 passengers, exceeding capacity 3, so the answer is NO.
Example 2
Input
2 4 2 1 5 2 3 7
Expected
YES
Explanation
The same overlap reaches 4 passengers, which is within capacity 4, so the answer is YES.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →