#line 1 "main.cpp" #include #include #include #include using namespace std; using lint = long long; void solve() { int n; lint m; cin >> n >> m; vector> ps(n); vector bs(n); for (int i = 0; i < n; ++i) { auto& [a, c] = ps[i]; auto& b = bs[i]; cin >> a >> b >> c; if (a > c) swap(a, c); } sort(bs.begin(), bs.end()); sort(ps.begin(), ps.end(), [](auto p, auto q) { return p.second > q.second; }); lint score = -1; for (int s = 0; s <= n; ++s) { lint sum = 0; bool ok = true; set ss(bs.begin(), bs.begin() + s); vector> qs; for (int i = 0; i < n; ++i) { auto [l, r] = ps[i]; auto it = ss.lower_bound(l); if (it != ss.begin()) { sum += r; ss.erase(--it); } else { qs.push_back(ps[i]); } } if (!ss.empty()) continue; reverse(qs.begin(), qs.end()); for (int i = 0; i < n - s; ++i) { auto [l, r] = qs[i]; auto b = bs[i + s]; if (r >= b) ok = false; sum += b; } if (ok) score = max(score, sum); } if (score == -1) { cout << "NO\n"; } else { cout << "YES\n"; cout << (score >= m ? "KADOMATSU!" : "NO") << "\n"; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }