#include using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a,Ts... ts){ return std::vector(ts...))>(a,make_v(ts...)); } int main() { int n, v, l; scanf("%d%d%d", &n, &v, &l); std::vector x(n + 1), y(n + 1); std::vector z(n + 1); for(int i = 1; i <= n; i++) scanf("%d%d%lld", &x[i], &y[i], &z[i]); x.push_back(l); y.push_back(0); z.push_back(0); std::vector dp(v + 1, 0); for(int i = 1; i < (int)x.size(); i++) { std::vector to(v + 1, 1LL << 60); int diff = x[i] - x[i -1]; for(int j = x[i] - x[i - 1]; j < v + 1; j++) { to[j - diff] = std::min(to[j - diff], dp[j]); if(j - diff + y[i] < v + 1) to[j - diff + y[i]] = std::min(to[j - diff + y[i]], dp[j] + z[i]); } dp.swap(to); } i64 ans = *std::min_element(begin(dp), end(dp)); if(ans == 1LL << 60) ans = -1; printf("%lld\n", ans); return 0; }