#include using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define LAR(a, b) ((a)=max((a),(b))) #define SML(a, b) ((a)=min((a),(b))) using ll = long long; using ld = long double; using vi = vector; using vl = vector; using pii = pair; using vpii = vector>; template using pque = priority_queue, greater>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif using pll = pair; map> g; pque que; set st; int main(){ int n; ll u, l; scanf("%d%lld%lld", &n, &u, &l); REP(i, n){ ll x, v, w; scanf("%lld%lld%lld", &x, &v, &w); REP(j, u){ g[x + j].EB(x + min(j+v, u), w); } } que.emplace(0, u); while(que.size()){ ll w = que.top().first, x = que.top().second; que.pop(); if(x >= l){ printf("%lld\n", w); return 0; } if(st.find(x) != st.end()) continue; st.emplace(x); for(auto &p : g[x]){ que.emplace(w + p.second, p.first); } } printf("-1\n"); }