#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include using namespace std; // #define int long long #define pb(x) push_back(x) #define m0(x) memset((x), 0, sizeof(x)) #define mm(x) memset((x), -1, sizeof(x)) //container #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end()); #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) // debug #define GET_VAR_NAME(variable) #variable #define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl; // bit_macro #define bit(n) (1LL << (n)) #define bitset(a, b) (a) |= (1 << (b)) #define bitunset(a, b) (a) |= ~(1 << (b)) #define bitcheck(a, b) ((((a) >> (b)) & 1) == 1) #define bitcount(a) __builtin_popcountll((a)) //typedef typedef long long lint; typedef complex Complex; typedef pair P; typedef tuple TP; typedef vector vec; typedef vector mat; //constant const int INF = (int)1e18; const int MOD = (int)1e9 + 7; const double EPS = (double)1e-10; const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1}; // template void chmax(T &a, T b) { a = max(a, b); } template void chmin(T &a, T b) { a = min(a, b); } // inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // struct Accelerate_Cin { Accelerate_Cin() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; }; //O(N) //充足可能性問題を解く。 //O(V+E) //強連結成分分解 const int MAX_V = 101010; int V; //頂点数 vector G[MAX_V]; //グラフの辺 vector rG[MAX_V]; //逆向きの辺 vector vs; //帰りがけ順の並び bool used[MAX_V]; //既に調べたかどうか int cmp[MAX_V]; //属する強連結成分のトポロジカル順序 void add_edge(int from, int to) { G[from].push_back(to); rG[to].push_back(from); } void dfs(int v) { used[v] = true; for (int i = 0; i < G[v].size(); i++) { if (!used[G[v][i]]) dfs(G[v][i]); } vs.push_back(v); } void rdfs(int v, int k) { used[v] = true; cmp[v] = k; for (int i = 0; i < rG[v].size(); i++) { if (!used[rG[v][i]]) rdfs(rG[v][i], k); } } void scc() { memset(used, 0, sizeof(used)); vs.clear(); for (int v = 0; v < V; v++) { if (!used[v]) dfs(v); } memset(used, 0, sizeof(used)); int k = 0; for (int i = vs.size() - 1; i >= 0; i--) { if (!used[vs[i]]) rdfs(vs[i], k++); } return; } /////////////////////////////////////////////////////////////////////// //ここからSAT int N; //リテラルの要素数。 int L[101010], R[101010], D[101010]; void solve() { V = 2 * N; //各リテラルをxで表す。対応は以下の通り //0~N-1 : x_i //N~2*N-1: ¬x_i //以下xリテラルの入力 for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { if (max(L[i], L[j]) < min(L[i] + D[i], L[j] + D[j])) { add_edge(i + N, j); add_edge(j + N, i); } if (max(R[i], R[j]) < min(R[i] + D[i], R[j] + D[j])) { add_edge(i, j + N); add_edge(j, i + N); } if (max(R[i], L[j]) < min(R[i] + D[i], L[j] + D[j])) { add_edge(i, j); add_edge(j + N, i + N); } if (max(L[i], R[j]) < min(L[i] + D[i], R[i] + D[i])) { add_edge(j, i); add_edge(i + N, j + N); } } } //強連結成分分解 scc(); for (int i = 0; i < N; i++) { if (cmp[i] == cmp[N + i]) { cout << "NO" << endl; return; } } cout << "YES" << endl; } signed main() { int M; cin >> N >> M; for (int i = 0; i < N; i++) { int l, r; cin >> l >> r; D[i] = abs(r - l); L[i] = l; R[i] = M - 1 - r; } solve(); return 0; }