Scenery
InterviewTime limit6sMemory limit512 MB
Given n time windows and a fixed photo duration t, decide whether all photos can be scheduled as non-overlapping intervals.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Intervals, Implementation
- Solved
- No attempts yet
Problem

Images by John Fowler, Carol Highsmith, and Richard Woodland
You spend one day of a trip to Rapid City photographing the South Dakota Badlands, a place known for its unusual land formations. You are an amateur photographer and very particular about light, so you picked one spot with a wide view and listed features you want to photograph from it.
Feature only looks the way you want while the sun sits in the right range of positions. You may start that photograph no earlier than time , and it must be finished by time . Repositioning the tripod and the camera takes a while, so every photograph takes exactly units of time. You photograph one feature at a time and never interrupt a photograph once it has started, so a photograph begun at time occupies the whole interval from to .
Decide whether you can photograph all features in one day.
Input
The first line contains two integers and (, ), where is the number of photographs you want and is the time one photograph takes.
Each of the next lines describes the time window of one photograph with two integers and (, ). You may begin that photograph no earlier than , and it must be finished by .
Output
Print yes if all photographs can be taken, and no otherwise.