#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #include #include #include #include #include #include #include #include using namespace std; template struct WeightedUnionFind{ vector par,siz; vector diff_weight; WeightedUnionFind(int n) { par.resize(n),siz.assign(n,1),diff_weight.resize(n); iota(par.begin(),par.end(),0); } int root(int x) { if(par[x] == x) return x; root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = root(par[x]); } T weight(int x) { root(x); return diff_weight[x]; } bool same(int x,int y) { return root(x) == root(y); } bool unite(int x,int y,T w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if(x == y) return false; if(siz[x] < siz[y]) swap(x,y),w *= -1; par[y] = x; siz[x] += siz[y]; diff_weight[y] = w; return true; } int size(int x) { return siz[root(x)]; } T diff(int x,int y) { assert(same(x,y)); return weight(y)-weight(x); } }; /* int main() */ /* { */ /* ios::sync_with_stdio(false); */ /* cin.tie(nullptr); */ /* int n,m; */ /* cin >> n >> m; */ /* WeightedUnionFind uf(n); */ /* for(int i = 0;i < m;i++) */ /* { */ /* int l,r,d; */ /* cin >> l >> r >> d; */ /* l--; r--; */ /* if(uf.same(l,r)) */ /* { */ /* long long diff = uf.diff(l,r); */ /* if(diff != d) */ /* { */ /* cout << "No" << endl; */ /* return 0; */ /* } */ /* } */ /* else */ /* { */ /* uf.unite(l,r,d); */ /* } */ /* } */ /* cout << "Yes" << endl; */ /* } */ void Main() { int N,K; cin >> N >> K; vector R(N); vector X(N); for(int i = 0;i < N;i++) { cin >> R[i] >> X[i]; } for(int i = 0;i < N;i++) { if(X[i] > (long long) (R[i] - i) * K) { cout << "No\n"; return; } } for(int i = 0;i < N;i++) { WeightedUnionFind uf(N + 1); for(int j = 0;j < N;j++) { if(j == i) { continue; } uf.unite(j,R[j],X[j]); } bool check = true; for(int j = 0;j < N;j++) { if(uf.same(j,j + 1)) { long long d = uf.diff(j,j + 1); if(0 <= d && d <= K); else { check = false; break; } } } cout << (check ? "Yes\n":"No\n"); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; /* cin >> tt; */ while(tt--) Main(); }