#if __INCLUDE_LEVEL__ == 0 #include using namespace std; #include __BASE_FILE__ namespace std::ranges::views { namespace { void solve() { int n, X, Y; cin >> tie(n, X, Y); vector f(X + 1, vector(Y + 1)); while (n--) { int a, b, c; cin >> tie(a, b, c); for (int x : iota(0, X + 1) | reverse) { for (int y : iota(0, Y + 1) | reverse) { if (x) { f[x][y] = max(f[x][y], f[x - 1][y]); } if (y) { f[x][y] = max(f[x][y], f[x][y - 1]); } if (a <= x && b <= y) { f[x][y] = max(f[x][y], f[x - a][y - b] + c); } } } } cout << f[X][Y] << '\n'; } } // namespace } // namespace std::ranges::views using views::solve; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); } #else // __INCLUDE_LEVEL__ namespace std { template istream& operator>>(istream& is, pair& p) { return is >> p.first >> p.second; } template istream& operator>>(istream& is, tuple& t) { return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } template istream& operator>>(istream& is, tuple&& t) { return is >> t; } template >* = nullptr> auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) { for (auto&& e : r) { is >> e; } return is; } template ostream& operator<<(ostream& os, const pair& p) { return os << p.first << ' ' << p.second; } template ostream& operator<<(ostream& os, const tuple& t) { auto f = [&os](const auto&... xs) -> ostream& { [[maybe_unused]] auto sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } template >* = nullptr> auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) { auto sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } } // namespace std #endif // __INCLUDE_LEVEL__