PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000240. Đi chung xe (Car Pooling)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đi chung xe (Car Pooling)

Car Pooling

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A car with capacity CC starts empty and travels only in the increasing-coordinate direction. There are mm groups; (p,s,t)(p,s,t) means pp passengers board at ss and leave at tt. At a shared stop, passengers leave before others board. Determine whether every group can be served without exceeding capacity.

Input

The first line contains m,Cm,C. Each of the next mm lines contains p,s,tp,s,t.

Output

Print true if possible, otherwise false (lowercase).

Subtasks

  • Subtask 1 (20 points): 1≤m≤501\le m\le 50; 1≤C≤1000001\le C\le 100000; 0≤s<t≤500\le s<t\le 50; 1≤p≤1001\le p\le 100.
  • Subtask 2 (30 points): 1≤m≤10001\le m\le 1000; 1≤C≤1000001\le C\le 100000; 0≤s<t≤10000\le s<t\le 1000; 1≤p≤1001\le p\le 100; s=0s=0 for every group/person.
  • Subtask 3 (50 points): 1≤m≤10001\le m\le 1000; 1≤C≤1000001\le C\le 100000; 0≤s<t≤10000\le s<t\le 1000; 1≤p≤1001\le p\le 100.

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.