Taking Medicine
Time limit1sMemory limit1024 MB
Decide whether three doses a day, each taken right after a meal within a fixed window, can keep the effect of K minutes active without a gap for N days.
- Level
Medium5 of 10
- Topics
- Greedy, Math, Simulation
- Solved
- No attempts yet
Problem
Yugyeom caught a cold, and the hospital gave him medicine for days. Yugyeom hates being sick, so once he starts the cold medicine, he wants the effect to last without a gap until he has finished the whole course.
Yugyeom must take the medicine three times a day, right after meals, and the effect lasts minutes. He can eat three meals a day, each within a fixed time window. The time spent eating and taking the medicine is ignored. Determine whether you can arrange the three meal times on each day so that the effect does not lapse until the last dose on day is taken.
Input
The first line contains the number of days and the duration of the effect , separated by a space.
The second line contains separated by spaces, where . Each pair gives the start and end, in minutes, of one of the three windows for meals. Day 1 runs from minute 0 to minute 1439, which is 1440 minutes in total.
All numbers in the input are integers.
Output
Print YES if the effect can last without a gap until the last dose on day is taken. Otherwise, print NO.