# Codeforces 1304 C. Air Conditioner

Description：

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 states: off, heating, and cooling. When it’s off, the restaurant’s temperature remains the same. When it’s heating, the temperature increases by in one minute. Lastly, when it’s cooling, the temperature decreases by

Each customer is characterized by three values: — the time (in minutes) when the i-th customer visits the restaurant, KaTeX parse error: Expected 'EOF', got '}' at position 5: l_[i}̲ — the lower bound of their preferred temperature range, and

A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the customer is satisfied if and only if the temperature is between and (inclusive) in the

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 . Description of the test cases follows.

The first line of each test case contains two integers and , where

Next, lines follow. The line of them contains three integers , and , where ti is the time when the customer visits, is the lower bound of their preferred temperature range, and

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

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).

Exampleinput

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

YES NO YES NO

Note

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

At minute, change the state to heating (the temperature is ).At minute, change the state to off (the temperature is ).At minute, change the state to heating (the temperature is , the 1-st customer is satisfied).At minute, change the state to off (the temperature is ).At minute, change the state to cooling (the temperature is , the At minute, the temperature will be 0, which satisfies the last customer. In the third case, Gildong can change the state to heating at

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

AC代码：#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define sd(n) scanf("%d", &n)#define sdd(n, m) scanf("%d%d", &n, &m)#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)#define pd(n) printf("%d\n", n)#define pc(n) printf("%c", n)#define pdd(n, m) printf("%d %d\n", n, m)#define pld(n) printf("%lld\n", n)#define pldd(n, m) printf("%lld %lld\n", n, m)#define sld(n) scanf("%lld", &n)#define sldd(n, m) scanf("%lld%lld", &n, &m)#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)#define sf(n) scanf("%lf", &n)#define sc(n) scanf("%c", &n)#define sff(n, m) scanf("%lf%lf", &n, &m)#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define ss(str) scanf("%s", str)#define rep(i, a, n) for (int i = a; i = a; i--)#define mem(a, n) memset(a, n, sizeof(a))#define debug(x) cout = mod) ans = ans % mod + mod; } a *= a; if (a >= mod) a = a % mod + mod; b >>= 1; } return ans;}

// 快速幂求逆元int Fermat(int a, int p) //费马求a关于b的逆元{ return qpow(a, p - 2, p);}

///扩展欧几里得ll exgcd(ll a, ll b, ll &x, ll &y){ if (b == 0) { x = 1; y = 0; return a; } ll g = exgcd(b, a % b, x, y); ll t = x; x = y; y = t - a / b * y; return g;}

const int N = 110;

struct node{ ll t, l, r;} a[N];int n, m, cnt;ll L, R, tim, res;int t;bool flag;

int main(){ sd(t); while (t--) { flag = 0; sdd(n, m); rep(i, 1, n) { slddd(a[i].t, a[i].l, a[i].r); } cnt = 1; rep(i, 2, n) { if (a[i].t == a[cnt].t) { if (a[cnt].r < a[i].l || a[i].r < a[cnt].l) { flag = 1; break; } a[cnt].l = max(a[i].l, a[cnt].l); a[cnt].r = min(a[i].r, a[cnt].r); } else a[++cnt] = a[i]; } if (flag == 1) { puts("NO"); continue; } L = m, R = m, res = 0; rep(i, 1, cnt) { tim = a[i].t - res; L = L - tim; R = R + tim; if (R < a[i].l || a[i].r < L) { flag = 1; break; } L = max(L, a[i].l); R = min(R, a[i].r); res = a[i].t; } if (flag == 1) { puts("NO"); continue; } puts("YES"); } return 0;}