➤ Problem Link : 1304C. Air Conditioner
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std;; #define ll long long int struct cust { ll tm,l,h; }; typedef struct cust Cust; int main() { int q; cin>>q; while(q--) { ll n,m,t,l,h; cin>>n>>m; Cust arr[n]; for(int i=0;i<n;i++) { cin>>arr[i].tm>>arr[i].l>>arr[i].h; } ll currL=m,currR=m; ll tempL,tempR,pt=0; bool flag=0; for(int i=0;i<n;i++) { t=arr[i].tm-pt; pt=arr[i].tm; tempR=currR+t; tempL=currL-t; currL=max(arr[i].l,tempL); currR=min(arr[i].h,tempR); if(currL>currR) { flag=1; break; } } if(flag) cout<<"NO\n"; else cout<<"YES\n"; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!