#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template vector make_v(U size, const T& init){ return vector(static_cast(size), init); } template auto make_v(U size, Ts... rest) { return vector(static_cast(size), make_v(rest...)); } template void chmin(T &a, const T &b){ a = (a < b ? a : b); } template void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n, W, l; cin >> n >> W >> l; vector xs, vs, ws; xs.emplace_back(0); vs.emplace_back(0); ws.emplace_back(0); for (int i = 0; i < n; ++i) { int x, v, w; scanf("%d %d %d", &x, &v, &w); xs.emplace_back(x); vs.emplace_back(v); ws.emplace_back(w); } xs.emplace_back(l); vs.emplace_back(0); ws.emplace_back(0); n = xs.size(); auto dp = make_v(n, W+1, INF); dp[0][W] = 0; for (int i = 0; i < n-1; ++i) { for (int j = W; j >= 0; --j) { chmin(dp[i][min(W, j+vs[i])],dp[i][j]+ws[i]); } for (int j = xs[i+1]-xs[i]; j <= W; ++j) { chmin(dp[i+1][j-(xs[i+1]-xs[i])], dp[i][j]); } } ll ans = INF; for (int i = 0; i <= W; ++i) { chmin(ans, dp.back()[i]); } cout << (ans == INF ? -1 : ans) << "\n"; return 0; }