A shared carpool van drives one straight route. It serves n ride requests. Ride i boards riders passengers at position board, who all leave at position alight (so they occupy the van over the half-open stretch [board, alight); a passenger who leaves at position x is no longer aboard at position x). The van has a fixed number of seats cap.
Determine whether the van can serve every ride without ever exceeding its seat capacity at any point of the route.
Line 1: two integers n and cap.
Next n lines: three integers board alight riders (with board < alight).
Print FEASIBLE if the number of passengers aboard never exceeds cap; otherwise print OVERLOADED.
Example 1
Input
2 4 0 2 3 2 5 3
Expected
FEASIBLE
Explanation
The first ride carries 3 passengers over [0,2); the second carries 3 over [2,5). They only touch at position 2, so at most 3 passengers are ever aboard, within the 4 seats: FEASIBLE.
Example 2
Input
2 4 0 3 3 1 4 2
Expected
OVERLOADED
Explanation
Over [1,3) both rides overlap, putting 3 + 2 = 5 passengers aboard, which exceeds the 4 seats: OVERLOADED.
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 →