#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } using mint = atcoder::modint998244353; using i128 = __int128_t; void solve() { ll n, y, z; cin >> n >> y >> z; vector> lcx(n); rep(i, 0, n) { cin >> lcx[i][1] >> lcx[i][0] >> lcx[i][2]; } sort(all(lcx)); reverse(all(lcx)); map mp; ll next_lv = -1; auto pop_lv = [&]() { while (!lcx.empty()) { auto& ar = lcx.back(); if (ar[0] > y) break; lcx.pop_back(); mp[ar[2]] += ar[1]; } if (!lcx.empty()) next_lv = min(z, lcx.back()[0]); else next_lv = z; }; pop_lv(); ll ans = 0; while (!mp.empty() && y < z) { auto itr = --mp.end(); auto [ad, cnt] = *itr; ll nd = (next_lv - y + ad - 1) / ad; if (nd >= cnt) { y += ad * cnt; ans += cnt; mp.erase(itr); if (y >= next_lv) pop_lv(); continue; } itr->second -= nd; y += ad * nd; ans += nd; pop_lv(); } if (y < z) cout << "-1\n"; else cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }