#include using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint n, V, L; cin >> n >> V >> L; vector x(n + 2), v(n + 2), w(n + 2); for (int i = 1; i <= n; ++i) { cin >> x[i] >> v[i] >> w[i]; } x[n + 1] = L; v[n + 1] = 0; w[n + 1] = 0; vector> dp(n + 2, (vector(V + 1, inf))); dp[0][V] = 0; for (int i = 1; i <= n + 1; ++i) { for (int j = 0; j <= V; ++j) { if (j + (x[i] - x[i - 1]) <= V) chmin(dp[i][j], dp[i - 1][j + (x[i] - x[i - 1])]); } for (int j = 0; j <= V; ++j) { chmin(dp[i][min(V, j + v[i])], dp[i][j] + w[i]); } } lint ret = inf; for (int j = 0; j <= V; ++j) { chmin(ret, dp[n + 1][j]); } if (ret == inf) cout << -1 << "\n"; else cout << ret << "\n"; return 0; }