#include int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int max = ri(); int l = ri(); struct Station { int pos; int max; int cost; }; Station stations[n]; for (auto &i : stations) i.pos = ri(), i.max = ri(), i.cost = ri(); int64_t dp[max + 1]; for (auto &i : dp) i = 1000000000000000000; dp[max] = 0; int last = 0; for (int i = 0; i < n; i++) { int move = stations[i].pos - last; last = stations[i].pos; for (int j = 0; j < move && j <= max; j++) dp[j] = 1000000000000000000; if (move) for (int j = move; j <= max; j++) dp[j - move] = dp[j], dp[j] = 1000000000000000000; for (int j = max; j >= 0; j--) { auto &target = dp[std::min(j + stations[i].max, max)]; target = std::min(target, dp[j] + stations[i].cost); } } int64_t res = 1000000000000000000; for (int i = l - last; i <= max; i++) res = std::min(res, dp[i]); printf("%" PRId64 "\n", res == 1000000000000000000 ? -1 : res); return 0; }