#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { ll n, m, l; cin >> n >> m >> l; ll x[n+2] = {}, v[n+2] = {}, w[n+2] = {}; x[n+1] = l; srep(i,1,n+1)cin >> x[i] >> v[i] >> w[i]; ll dp[n+2][m+1]; ll INF = 1001001001001001001; rep(i,n+2)rep(j,m+1)dp[i][j] = INF; dp[0][m] = 0; rep(i,n+1){ int d = x[i+1] - x[i]; rep(j,m+1){ if(j < d)continue; dp[i+1][j-d] = min(dp[i+1][j-d], dp[i][j]); int nv = min(m, j-d+v[i+1]); dp[i+1][nv] = min(dp[i+1][nv], dp[i][j] + w[i+1]); } } ll ans = INF; rep(j,m+1)ans = min(ans, dp[n+1][j]); if(ans == INF)ans = -1; cout << ans << endl; return 0; }