#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b struct SegmentTree{ using F=function; int sz; vector seg; const F f; const Monoid gen; SegmentTree(int n,const F f,const Monoid &gen):f(f),gen(gen){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,const Monoid &x){ k+=sz; seg[k]=x; while(k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } // [a,b) Monoid query(int a,int b){ Monoid L=gen,R=gen; for(a+=sz,b+=sz;a>=1,b>>=1){ if(a&1) L=f(L,seg[a++]); if(b&1) R=f(seg[--b],R); } return f(L,R); } Monoid operator[](const int &k)const { return seg[k+sz]; } }; ll f(ll a,ll b){ return (a>N>>V>>L; ll dp[N+2][V+1]; rep(i,N+2)rep(j,V+1)dp[i][j]=LINF; dp[0][V]=0; ll pre=0; rep(i,N){ ll x,v,w;cin>>x>>v>>w; ll dis=x-pre; for(int j=0;j+dis<=V;j++){ dp[i+1][j]=dp[i][j+dis]; } SegmentTree seg(V+1,f,LINF); rep(j,V+1) seg.set(j,dp[i+1][j]); seg.build(); for(int j=V;j>=0;j--){ chmin(dp[i+1][j],seg.query(max(0ll,j-v),j)+w); } pre=x; } ll ans=LINF; ll dis=L-pre; for(int i=0;i+dis<=V;i++){ dp[N+1][i]=dp[N][i+dis]; } rep(i,V+1) chmin(ans,dp[N+1][i]); cout<<(ans