#include #include #include using lint = long long; constexpr lint INF = 1LL << 60; void solve() { int n, m, l; std::cin >> n >> m >> l; std::vector dp(m + 1, 0); auto ndp = dp; int px = 0; while (n--) { int x, v, w; std::cin >> x >> v >> w; std::fill(ndp.begin(), ndp.end(), INF); for (int i = 0; i + (x - px) <= m; ++i) { ndp[i] = dp[i + (x - px)]; } for (int i = m; i >= 0; --i) { ndp[i] = std::min(ndp[i], ndp[std::max(i - v, 0)] + w); if (i + 1 <= m) ndp[i] = std::min(ndp[i], ndp[i + 1]); } std::swap(dp, ndp); px = x; } { int x = l; std::fill(ndp.begin(), ndp.end(), INF); for (int i = 0; i + (x - px) <= m; ++i) { ndp[i] = dp[i + (x - px)]; } std::swap(dp, ndp); } auto ans = *std::min_element(dp.begin(), dp.end()); std::cout << (ans == INF ? -1 : ans) << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }