440. Car Pooling
MediumPrefix SumSimulation
A car with the given capacity drives east. Each trip has p passengers picked up at kilometre from and dropped at kilometre to. Print YES if all trips fit, else NO.
Input format
Line 1: n capacity Next n lines: p from to
Output format
YES or NO
Example 1
Input
2 4 2 1 5 3 3 7
Output
NO
Example 2
Input
2 5 2 1 5 3 3 7
Output
YES
Constraints
1 ≤ n ≤ 1000 0 ≤ from < to ≤ 1000
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…