#pragma GCC optimize ("O3") #pragma GCC target ("avx") //#pragma GCC optimize ("Ofast") #include #include #include #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rfor(i, m, n) for (int i = (m); i >= (n); --i) using ll = long long; #ifdef _WIN32 #define gc _getchar_nolock #define pc _putchar_nolock #else #define gc getchar_unlocked #define pc putchar_unlocked #endif #if __has_include("dump.hpp") #include "dump.hpp" #else #define dump(...) ((void)0) #endif inline void inui(int& v)noexcept { v = 0; for (char c = gc(); isdigit(c); c = gc()) v = v * 10 + (c - '0'); } inline void inul(ll& v)noexcept { v = 0; for (char c = gc(); isdigit(c); c = gc()) v = v * 10 + (c - '0'); } inline void ini(int& v)noexcept { v = 0; char c = gc(); bool f = false; if (c == '-') { f = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (f)v = -v; } inline void inl(ll& v)noexcept { v = 0; char c = gc(); bool f = false; if (c == '-') { f = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (f)v = -v; } inline void ins(char* c, int n)noexcept { while (n--) { *c = gc(); ++c; } } inline void outi(int v)noexcept { if (v < 0)pc('-'), v = -v; char b[10]; int n = 0; while (v)b[n++] = '0' + v % 10, v /= 10; if (!n)b[n++] = '0'; while (n--)pc(b[n]); } inline void outui(int v)noexcept { char b[10]; int n = 0; while (v)b[n++] = '0' + v % 10, v /= 10; if (!n)b[n++] = '0'; while (n--)pc(b[n]); } inline void outl(ll v)noexcept { if (v < 0)pc('-'), v = -v; char b[20]; int n = 0; while (v)b[n++] = '0' + v % 10, v /= 10; if (!n)b[n++] = '0'; while (n--)pc(b[n]); } inline void outul(ll v)noexcept { char b[20]; int n = 0; while (v)b[n++] = '0' + v % 10, v /= 10; if (!n)b[n++] = '0'; while (n--)pc(b[n]); } constexpr int MAX_N = 2005, MAX_V = 2005; constexpr ll inf = 1e16; int N, V, L; int x[MAX_N], v[MAX_N]; ll w[MAX_N], dp[MAX_V + 1]; int main() { inui(N); inui(V); inui(L); rep(i, N) { inui(x[i + 1]); inui(v[i + 1]); inul(w[i + 1]); } x[N + 1] = L; N += 2; rep(i, V)dp[i] = inf; FOR(i, 1, N) { int dist = x[i] - x[i - 1]; if (dist > V) { puts("-1"); return 0; } rep(i, V + 1 - dist) { dp[i] = dp[i + dist]; } FOR(i, V + 1 - dist, V + 1) { dp[i] = inf; } rrep(j, V + 1) { int k = min(V, j + v[i]); dp[k] = min(dp[k], dp[j] + w[i]); } } ll ans = inf; rep(i, V + 1) { if (ans > dp[i]) ans = dp[i]; } if (ans != inf) { outul(ans); pc('\n'); } else { puts("-1"); } }