#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() void chmin(ll &x, ll y) { x = min(x, y); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; ll V, L; cin >> N >> V >> L; vector X(N), v(N), W(N); rep(i, N) cin >> X[i] >> v[i] >> W[i]; vector dp(V + 1, LLONG_MAX); if (V >= X[0]) { dp[V - X[0]] = 0; } rep(i, N) { repr(j, V + 1) if (dp[j] != LLONG_MAX) { chmin(dp[min(V, j + v[i])], dp[j] + W[i]); } ll d = (i + 1 < N ? X[i + 1] : L) - X[i]; for (int j = 0; j <= V; j++) { dp[j] = j + d <= V ? dp[j + d] : LLONG_MAX; } } ll ans = *min_element(range(dp)); if (ans == LLONG_MAX) ans = -1; cout << ans << endl; }