C. Air Conditioner

news/2024/10/18 8:25:01/

链接:https://codeforces.com/contest/1304/problem/C

Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.

Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.

The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.

Each customer is characterized by three values: titi — the time (in minutes) when the ii-th customer visits the restaurant, lili — the lower bound of their preferred temperature range, and hihi — the upper bound of their preferred temperature range.

A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the ii-th customer is satisfied if and only if the temperature is between lili and hihi (inclusive) in the titi-th minute.

Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.

Input

Each test contains one or more test cases. The first line contains the number of test cases qq (1≤q≤5001≤q≤500). Description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n≤1001≤n≤100, −109≤m≤109−109≤m≤109), where nn is the number of reserved customers and mm is the initial temperature of the restaurant.

Next, nn lines follow. The ii-th line of them contains three integers titi, lili, and hihi (1≤ti≤1091≤ti≤109, −109≤li≤hi≤109−109≤li≤hi≤109), where titi is the time when the ii-th customer visits, lili is the lower bound of their preferred temperature range, and hihi is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.

The customers are given in non-decreasing order of their visit time, and the current time is 00.

Output

For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".

You can print each letter in any case (upper or lower).

Example


input

Copy

4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0

output

Copy

YES
NO
YES
NO

Note

In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:

  • At 00-th minute, change the state to heating (the temperature is 0).
  • At 22-nd minute, change the state to off (the temperature is 2).
  • At 55-th minute, change the state to heating (the temperature is 2, the 11-st customer is satisfied).
  • At 66-th minute, change the state to off (the temperature is 3).
  • At 77-th minute, change the state to cooling (the temperature is 3, the 22-nd customer is satisfied).
  • At 1010-th minute, the temperature will be 0, which satisfies the last customer.

In the third case, Gildong can change the state to heating at 00-th minute and leave it be. Then all customers will be satisfied. Note that the 11-st customer's visit time equals the 22-nd customer's visit time.

In the second and the fourth case, Gildong has to make at least one customer unsatisfied.

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,m,s,max1,min1,l,r,k,tl,tr;
long long a[1000001];
int main()
{cin>>t;while(t--){cin>>n>>m;a[0]=0;max1=m;min1=m;int flag=1;for(int i=1;i<=n;i++){cin>>a[i]>>l>>r;k=a[i]-a[i-1];tl=min1-k;tr=max1+k;if(tl>r||tr<l){flag=0;}else{max1=min(tr,r);min1=max(tl,l);}}if(flag==0)cout<<"NO"<<endl;elsecout<<"YES"<<endl;}
}

 


http://www.ppmy.cn/news/702532.html

相关文章

Up in the Air-2

Speech on trip. How much does your life weigh(多重)? Imagine for a second that you’re carrying a backpack&#xff08;背一个包&#xff09;. I want you to feel the straps&#xff08;肩带&#xff09; on your shoulders. Feel them? I want you to pack it wit…

关于LiveData全面详解(附事件总线)

作者&#xff1a;苏火火 前言 MVVM 架构模式中&#xff0c;ViewModel 是不会持有宿主的信息&#xff0c;业务逻辑在 ViewModels 层中完成&#xff0c;而不是在 Activities 或 Fragments 中。LiveData 在里面担任数据驱动的作用&#xff1a; 以往我们使用 Handler&#xff0c;E…

Airflow简介

1、什么是Airflow Airflow 是一个 Airbnb 的 Workflow 开源项目&#xff0c;使用Python编写实现的任务管理、调度、监控工作流平台。Airflow 是基于DAG(有向无环图)的任务管理系统&#xff0c;可以简单理解为是高级版的crontab&#xff0c;但是它解决了crontab无法解决的任务…

Air Video

http://baike.baidu.com/view/8552809.htm#1 百度首页 | 登录注册 新闻网页贴吧知道MP3图片视频地图百科文库 帮助 首页自然文化地理历史生活社会艺术人物经济科技体育图片数字博物馆核心用户百科商城 求助编辑 Air Video 目录 简介 使用教程 展开 简介 使用教程 展开 编辑本段…

AirTest

Airetest是由网易游戏推出的一个跨平台的、基于图像识别的UI自动化测试框架&#xff0c;适用于游戏和APP&#xff0c;支持Windows、Android和ios&#xff0c;基于python进行编码。在此基础上&#xff0c;还推出了AiretestIDE&#xff0c;一款UI自动化测试编辑器&#xff0c;Poc…

Air Conditioners

题目链接&#xff1a;https://codeforces.com/problemset/problem/1547/E 这个题意比较容易理解&#xff0c;就是让我们求每个空格的最低温度&#xff0c;这道题目可以用最短路解决&#xff0c;我们可以让每两个相邻的点的距离为1&#xff0c;然后建立一个虚拟源点&#xff0c…

AIR是什么?.air文件如何打开?flex如何运行air文件

1 安装Adobe AIR 运行时&#xff0c;和java的JVM类似。 Adobe AIR 运行时允许在桌面运行AIR应用程序&#xff0c;脱离游览器的束缚。 下载安装文件 http://labs.adobe.com/downloads/air.html 在下载页面有样例程序&#xff08;Sample Applications&#xff09;http://labs…

ADOBE AIR是什么?

AIR是一项自2007年来备受推崇的新型技术&#xff0c;它又可以说是对新老技术的结合体。通过这样的结合&#xff0c;我们发现&#xff0c;确实让客户感受得到了很好的改善&#xff0c;比如说&#xff1a;客户更愿意多进行一些操作、更愿意去体验一下新的功能。因为它实在太迷人了…