题解 CF1304C 【Air Conditioner】
Description
有一家餐馆,初始温度为
现在有
(
Solution
我们考虑维护对于每个时刻,温度可能取到的区间
不难发现,一个时刻时,温度区间是
那么我们可以按顾客到达的顺序来处理。维护温度可能的区间
又因为要满足第
取交集:
如果此时我们发现集合为空(NO。
如果我们的程序一直处理完了 YES。
时间复杂度
Code
(其实不用 sort 的,题目说了输入按时间顺序)
#include <bits/stdc++.h>
using namespace std;
struct customer
{
int t, l, r;
bool operator < (const customer& ano) const
{
return t < ano.t;
}
}c[101];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d %d %d", &c[i].t, &c[i].l, &c[i].r);
sort(c + 1, c + n + 1);
int l = m, r = m;
bool flag = true;
for(int i = 1; i <= n; i++)
{
int d = c[i].t - c[i - 1].t;
l -= d;
r += d;
l = max(l, c[i].l);
r = min(r, c[i].r);
if(l > r)
{
flag = false;
break;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}