/*    ∫ ∫ ∫    ノヽ   (_  )  (_    ) (______ )  ヽ(´・ω・)ノ     |  /    UU */ #pragma region macro #include typedef long long int64; using namespace std; typedef vector vi; const int MOD = (int)1e9 + 7; const int64 INF = 1LL << 62; const int inf = 1<<30; const char bn = '\n'; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream& operator<<(ostream& os, const vector &V){ int N = V.size(); REP(i,N){ os << V[i]; if (i!=N-1) os << " "; } os << "\n"; return os; } template ostream& operator<<(ostream& os, pair const&P){ os << "("; os << P.first; os << " , "; os << P.second; os << ")"; return os; } template ostream& operator<<(ostream& os, set &S){ auto it=S.begin(); while(it!=S.end()){ os << *it; os << " "; it++; } os << "\n"; return os; } template ostream& operator<<(ostream& os, deque &q){ for(auto it=q.begin();it ostream& operator<<(ostream& os, map const&M){ for(auto e:M){ os<> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)}; #pragma endregion //fixed<> N >> V >> L; vector> XVW; REP(i,N){ int64 x,v,w; cin >> x >> v >> w; XVW.emplace_back(x,v,w); } vector> DP(N+1,vector(V+1,INF)); DP[0][V] = 0; int64 before_x = 0; REP(i,N){ int64 x,v,w; tie(x,v,w) = XVW[i]; int64 dist = x-before_x; REP(gas,V+1){ int remain = gas-dist; if(remain<0) continue; chmin(DP[i+1][remain], DP[i][gas]); chmin(DP[i+1][min(int64(V),remain+v)], DP[i][gas] + w); } before_x = x; } int64 ans = INF; for(int gas=L-before_x; gas<=V; gas++) chmin(ans, DP.back()[gas]); if(ans==INF) cout << -1 << bn; else cout << ans << endl; }