#include using namespace std; int main() { constexpr int64_t inf = 1e18; int n, vmax, l; cin >> n >> vmax >> l; vector x(n + 2), v(n + 2), w(n + 2); for (int i = 0; i < n; i++) { cin >> x.at(i + 1) >> v.at(i + 1) >> w.at(i + 1); } x.at(n + 1) = l; vector> dp(n + 2, vector(vmax + 1, inf)); // remaining, cost dp.at(0).at(vmax) = 0; for (int i = 0; i <= n; i++) { int used = x.at(i + 1) - x.at(i); for (int j = 0; j <= vmax; j++) { int prev_j = j + used, prev_j_stop = max(0, prev_j - v.at(i + 1)); if (prev_j <= vmax) { dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(prev_j)); } if (prev_j_stop <= vmax) { dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(prev_j_stop) + w.at(i + 1)); } } } int64_t ans = inf; for (int i = 0; i <= vmax; i++) { ans = min(ans, dp.at(n + 1).at(i)); } if (ans == inf) { cout << -1 << endl; } else { cout << ans << endl; } }