#include using namespace std; using lint = long long; using pint = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template vector sort_unique(vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template istream &operator>>(istream &is, vector &vec) { for (auto &v : vec) is >> v; return is; } template ostream &operator<<(ostream &os, const vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } #ifdef HITONANODE_LOCAL const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m"; #define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl #else #define dbg(x) (x) #endif void bad() { puts("NO"); exit(0); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; lint M; cin >> N >> M; vector B(N); vector AC; REP(i, N) { int a, c; cin >> a >> B[i] >> c; if (a > c) swap(a, c); AC.emplace_back(a, c); } sort(AC.begin(), AC.end(), [](const auto &l, const auto &r) { return l.second < r.second; }); sort(B.begin(), B.end()); const auto zaatsu = sort_unique(B); vector sh(N); REP(i, N) sh[i] = lower_bound(zaatsu.begin(), zaatsu.end(), AC[i].first) - zaatsu.begin(); lint ret = -1; vector adds; vector cnt(zaatsu.size() + 1); vector used(N); lint bupsum = accumulate(B.begin(), B.end(), 0LL); auto try_to_solve = [&]() { lint tmp = 0; for (auto i : adds) tmp += AC[i].second; vector cs; REP(i, N) if (!used[i]) cs.emplace_back(AC[i].second); REP(i, cs.size()) if (B[i + adds.size()] <= cs[i]) return; tmp += bupsum; chmax(ret, tmp); }; REP(i, N) { try_to_solve(); auto t = lower_bound(zaatsu.begin(), zaatsu.end(), B[i]) - zaatsu.begin(); REP(j, t + 1) cnt[j]++; int h = 0; while (cnt[h] > 0) h++; int amax = -1; REP(i, N) if (!used[i] and sh[i] >= h) { if (amax < 0 or AC[amax].second < AC[i].second) { amax = i; } } if (amax < 0) break; used[amax] = 1; REP(j, sh[amax]) cnt[j]--; bupsum -= B[i]; adds.emplace_back(amax); } try_to_solve(); if (ret < 0) bad(); puts("YES"); if (ret < M) bad(); puts("KADOMATSU!"); }