PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000240. Đi chung xe (Car Pooling)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đi chung xe (Car Pooling)
Car Pooling
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A car with capacity starts empty and travels only in the increasing-coordinate direction. There are groups; means passengers board at and leave at . At a shared stop, passengers leave before others board. Determine whether every group can be served without exceeding capacity.
Input
The first line contains . Each of the next lines contains .
Output
Print true if possible, otherwise false (lowercase).
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; for every group/person.
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
2 4
2 1 5
3 3 7
Output
false
Explanation
Between 3 and 5 the occupancy is 5, exceeding 4.
Example 2
Input
2 5
2 1 5
3 3 7
Output
true
Explanation
Peak occupancy equals capacity 5.
Example 3
Input
2 3
3 0 2
3 2 4
Output
true
Explanation
At 2 the first group leaves before the second boards.