Company: Codeville

Difficulty: medium

Problem Statement

Thermostat Control Aryan's thermostat starts switched off at temperature `0`. At any whole minute he may set it to heating, cooling, or off. Heating changes the temperature by `+1` per minute, cooling by `-1` per minute, and off leaves it unchanged. There are friends arriving at specified minutes. Friend `i` is comfortable only if the temperature at minute `t[i]` is between `l[i]` and `r[i]`, inclusive. Determine whether all friends can be made comfortable. Input The first line contains `T`, the number of test cases. Each test case starts with `n` (`1 <= n <= 2*10^5`). Then follow `n` lines with `t[i]`, `l[i]`, and `r[i]`; times are non-decreasing. The sum of `n` over all test cases does not exceed `2*10^5`. Output For every test case print `YES` if a valid schedule exists, otherwise print `NO`. Notes The temperature can be changed by at most one per minute. Multiple friends may arrive at the same minute, so all of their ranges must contain one common temperature.

More Codeville OA questionsInterview experiences