#include #include #include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const ll INF=1LL<<60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll K; cin>>N>>K; vectorR(N); vectorX(N); for(int i=0;i>R[i]>>X[i]; R[i]--; } for(int i=0;iA(N),S(N+1); bool ok=true; for(int j=N-1;j>i;j--){ A[j]=X[j]-(S[j+1]-S[R[j]+1]); if(A[j]<0||A[j]>K){ ok=false; break; } S[j]=A[j]+S[j+1]; } if(!ok){ cout<<"No"<<"\n"; continue; } /* A[i] = x */ vectorx(i+1),y(N+1); x[i]=1; y[i]=1; S[i]=S[i+1]; for(int j=i-1;j>=0;j--){ A[j]=X[j]-(S[j+1]-S[R[j]+1]); x[j]=-(y[j+1]-y[R[j]+1]); if(x[j]==0&&(A[j]<0||A[j]>K)){ ok=false; break; } S[j]=A[j]+S[j+1]; y[j]=x[j]+y[j+1]; } if(!ok){ cout<<"No"<<"\n"; }else{ ll l=-INF,r=INF; for(int j=i;j>=0;j--){ if(x[j]==1){ chmax(l,-A[j]); chmin(r,K-A[j]); }else if(x[j]==-1){ chmax(l,A[j]-K); chmin(r,A[j]); } } if(l>r)cout<<"No"<<"\n"; else cout<<"Yes"<<"\n"; } } }