//#include #include using namespace std; typedef long long ll; typedef pair p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout< x, y, w; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> v >> l; x.resize(n + 2); y.resize(n + 2); w.resize(n + 2); x[0] = 0; y[0] = 0; w[0] = 0; rep(i, n) { cin >> x[i + 1] >> y[i + 1] >> w[i + 1]; } x[n + 1] = l; y[n + 1] = 0; w[n + 1] = 0; vector> dp(n + 2, vector(v + 1, LINF)); dp[0][v] = 0; rep(i, n + 1) { rep(j,v+1){ if(j-x[i+1]+x[i]>=0){ dp[i + 1][j - x[i + 1] + x[i]] = min(dp[i][j], dp[i + 1][j - x[i + 1] + x[i]]); } } for(int j=v;j>=0;j--){ if(j-y[i+1]>=0){ dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-y[i+1]]+w[i+1]); } } } ll ans=LINF; rep(i,v+1){ chmin(ans,dp[n+1][i]); } /* rep(i,n+2){ debug(dp[i]); } */ if(ans==LINF)cout<<-1<<"\n"; else cout<