/* -*- coding: utf-8 -*- * * 1037.cc: No.1037 exhausted - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 2000; const int MAX_V = 2000; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; /* global variables */ int xs[MAX_N + 2], vs[MAX_N + 1], wis[MAX_N + 1]; ll dp[MAX_N + 2][MAX_V + 1]; /* subroutines */ inline void setmin(ll &a, ll b) { if (a > b) a = b; } /* main */ int main() { int n, v, l; scanf("%d%d%d", &n, &v, &l); for (int i = 1; i <= n; i++) scanf("%d%d%d", xs + i, vs + i, wis + i); xs[0] = vs[0] = wis[0] = 0; xs[n + 1] = l; for (int i = 0; i <= n + 1; i++) fill(dp[i], dp[i] + v + 1, LINF); dp[0][v] = 0; for (int i = 0; i <= n; i++) for (int j = 0; j <= v; j++) if (dp[i][j] < LINF) { int l = xs[i + 1] - xs[i]; if (j >= l) setmin(dp[i + 1][j - l], dp[i][j]); if (vs[i] > 0) { int j1 = min(v, j + vs[i]); if (j1 >= l) setmin(dp[i + 1][j1 - l], dp[i][j] + wis[i]); } } ll mind = LINF; for (int j = 0; j <= v; j++) setmin(mind, dp[n + 1][j]); printf("%lld\n", (mind >= LINF) ? -1LL : mind); return 0; }