/* ---------- STL Libraries ---------- */ // IO library #include #include #include #include #include // algorithm library #include #include #include #include #include #include // container library #include #include #include #include #include #include #include #include #include #include #include // type #include #include /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; #define P pair /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* ---------- Functions */ template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, V, L; cin >> N >> V >> L; vector x(N+2); vector f(N+2); vector w(N+2); for (int i = 1; i <= N ;i++) cin >> x[i] >> f[i] >> w[i]; x[0] = 0; f[0] = 0; w[0] = 0; x[N+1] = L; f[N+1] = 0; w[N+1] = 0; vector dp1(V+1, INF); vector dp2(V+1, INF); vector dp3(V+1, INF); dp1[V] = 0; for (int i = 0; i <= N; i++) { int dis = x[i+1] - x[i]; dp2.assign(V+1, INF); for (int v = V; v >= 0; v--) { if (v - dis < 0) break; dp2[v-dis] = dp1[v]; } dp3 = dp2; for (int v = 0; v <= V; v++) { chmin(dp3[min(V, v + f[i+1])], dp2[v] + w[i+1]); } swap(dp1, dp3); } int ret = INF; for (int d : dp1) ret = min(ret, d); if (ret == INF) ret = -1; cout << ret << endl; return 0; }