#include #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; template inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } int N, V, L, x[2010], v[2010], w[2010]; ll dp[2010][2010]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> V >> L; REP(i, 1, N+1) cin >> x[i] >> v[i] >> w[i]; x[0] = w[0] = 0; v[0] = V; x[N+1] = L; rep(i, 2010) rep(j, 2010) dp[i][j] = (1LL<<60); dp[0][0] = 0; rep(i, N+1) rep(j, V+1) { if(min(V, j+v[i])-(x[i+1]-x[i]) >= 0) chmin(dp[i+1][min(V, j+v[i])-(x[i+1]-x[i])], dp[i][j]+w[i]); if(j-(x[i+1]-x[i]) >= 0) chmin(dp[i+1][j-(x[i+1]-x[i])], dp[i][j]); } ll ans = (1LL<<60); rep(j, V+1) { chmin(ans, dp[N+1][j]); } if(ans == (1LL<<60)) ans = -1; cout << ans << '\n'; return 0; }