#include #include #include int main() { using namespace std; constexpr int INF = 1'000'000'000; int n, max_w, d; cin >> n >> max_w >> d; vector> dp(2, vector(max_w + 1, -INF)); for (auto&& i : dp) i.at(0) = 0; for (int t, w, v, i = 0; i < n; ++i) { cin >> t >> w >> v; for (int j = max_w; j >= w; --j) dp.at(t).at(j) = max(dp.at(t).at(j), dp.at(t).at(j - w) + v); } int ans = 0; for (int i = 0; i <= max_w; ++i) for (int j = max(0, i - d); j <= min(max_w - i, i + d); ++j) ans = max(ans, dp.at(0).at(i) + dp.at(1).at(j)); cout << ans << '\n'; return 0; }