WOSS Dual Olympiad 2023 S2: Geese Attack

View as PDF

Submit solution


Points: 10
Time limit: 2.0s
Memory limit: 1G

Authors:
Problem type

The sky darkens... it is raining geese. Oli is on a strip of land that is N units long. He initially starts at unit 0 on the left, and every second he can teleport an integer from 0 to K units, either left or right. He cannot travel beyond unit N or beyond unit 0 on the strip. M squadrons of geese will rain from the sky. The ith squadron hits the ground in t_i + 0.5 seconds from now, temporarily vaporizing the area stretching from units a_i to b_i inclusive. Can he avoid all the geese without getting vaporized? The strip when N=12 is shown below.

Constraints

1 \leq N, K \leq 10^9

1 \leq M \leq 10^4

0 \leq a_i \leq b_i \leq N

1 \leq t_i \leq 10^4

Input Specification

The first line of input contains 3 space-separated integers, N, M, and K.

The next M lines each contain 3 space-separated integers, a_i, b_i, and t_i. These will be sorted in increasing order of t_i, all times are distinct.

Output Specification

Output a single line containing YES if he can survive and NO if he cannot.

Sample Input 1

1000 2 1
300 600 1000
0 400 1001

Sample Output 1

YES

Sample Input 2

10 6 1
0 4 11
3 7 12
8 10 13
1 2 15
4 9 16
1 7 17

Sample Output 2

YES

Sample Input 3

5 3 3
0 0 1
2 5 2
0 4 3

Sample Output 3

NO

Comments

There are no comments at the moment.