#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define repk(i, k, n) for (int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 #define mod3 100000007 #define vi vector #define vs vector #define vc vector #define vl vector #define vb vector #define vvi vector> #define vvc vector> #define vvl vector> #define vvb vector> #define vvvi vector>> #define vvvl vector>> #define pii pair #define pil pair #define pli pair #define pll pair #define vpii vector> #define vpll vector> #define vvpii vector>> #define vvpll vector>> template void debug(T e) { cerr << e << endl; } template void debug(vector &v) { rep(i, v.size()) { cerr << v[i] << " "; } cerr << endl; } template void debug(vector> &v) { rep(i, v.size()) { rep(j, v[i].size()) { cerr << v[i][j] << " "; } cerr << endl; } } template void debug(vector> &v) { rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; } } template void debug(set &st) { for (auto itr = st.begin(); itr != st.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template void debug(multiset &ms) { for (auto itr = ms.begin(); itr != ms.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template void debug(map &mp) { for (auto itr = mp.begin(); itr != mp.end(); itr++) { cerr << itr->first << " " << itr->second << endl; } } void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << H << " "; debug_out(T...); } using mint = modint998244353; void debug_mint1(vector &vec) { for (int i = 0; i < vec.size(); i++) { cerr << vec[i].val() << " "; } cerr << endl; } void debug_mint2(vector> &vec) { for (int i = 0; i < vec.size(); i++) { for (int j = 0; j < vec[i].size(); j++) { cerr << vec[i][j].val() << " "; } cerr << endl; } } ll INF = 4000000000000000004LL; int main() { ll N, Y, Z; cin >> N >> Y >> Z; vector C(N); vector L(N); vector X(N); rep(i, N){ cin >> C[i] >> L[i] >> X[i]; } priority_queue pque; for (ll i = 0; i < N; i++){ if (L[i] <= Y){ pque.push(make_pair(X[i], C[i])); } } vector p(N); rep(i, N){ p[i] = make_pair(L[i], i); } sort(all(p)); ll now_cur = 0; for (ll i = 0; i < N; i++){ if (p[i].first > Y) break; now_cur++; } if (now_cur == 0){ cout << -1 << endl; return 0; } ll ans = 0; ll now_lv = Y; while (pque.size()){ debug_out(now_lv, ans, now_cur); if (now_lv >= Z) break; pll pp = pque.top(); ll up_lv = pp.first; ll cnts = pp.second; ll nxt_lv = INF; if (now_cur < N){ nxt_lv = p[now_cur].first; } if (up_lv >= (nxt_lv - now_lv) / cnts){ ll rem = (nxt_lv - now_lv + up_lv - 1) / up_lv; if (rem >= (Z - now_lv) / up_lv){ cout << ans + (Z - now_lv + up_lv - 1) / up_lv << endl; return 0; } else{ now_lv += up_lv * rem; pp.second -= rem; ans += rem; while (now_cur < N){ if (p[now_cur].first > now_lv){ break; } pque.push(make_pair(X[p[now_cur].second], C[p[now_cur].second])); now_cur++; } } } else if (up_lv >= (Z - now_lv) / cnts){ cout << ans + (Z - now_lv + up_lv - 1) / up_lv << endl; return 0; } else{ ans += cnts; now_lv += up_lv * cnts; pque.pop(); } // debug_out(now_lv, ans, now_cur); } if (now_lv < Z) cout << -1 << endl; else cout << ans << endl; }