#pragma GCC optimize("Ofast") #include #include #include using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } void print() { cout << "\n"; } template void print(const T &x, const Args &... args) { cout << x << " "; print(args...); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,V,L; cin >> N >> V >> L; vector x(N+1),v(N+1),w(N+1); rep(i,N) cin >> x[i] >> v[i] >> w[i]; x[N] = L; vector> dp(N+2, vector(V+1,1e18)); dp[0][V] = 0; int cur = 0; rep(i,N+1) { int d = x[i] - cur; rep(j,V+1) { if (j < d or dp[i][j]==1e18) continue; chmin(dp[i+1][j-d],dp[i][j]); int nv = min(V,j-d+v[i]); chmin(dp[i+1][nv],dp[i][j]+w[i]); } cur = x[i]; } ll ans = 1e18; rep(i,V+1) chmin(ans,dp[N+1][i]); cout << (ans==1e18 ? -1 : ans) << ln; }