#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct s { ll c, l, x; }; int main() { ll n, y, z; cin >> n >> y >> z; vector v(n); for (auto &[c, l, x] : v) cin >> c >> l >> x; v.push_back({0LL, 1LL << 60, 0LL}); sort(v.begin(), v.end(), [&](s a, s b) { return a.l < b.l; }); priority_queue> q; int ind = 0; ll ans = 0; while (v[ind].l <= y) { q.push({v[ind].x, v[ind].c}); ind++; } while (!q.empty()) { while (v[ind].l <= y) { q.push({v[ind].x, v[ind].c}); ind++; } if ((z <= v[ind].l) && y + __int128(q.top().first) * q.top().second >= z) { cout << ans + (z - y - 1) / (q.top().first) + 1 << endl; return 0; } auto p = q.top(); q.pop(); ll r = (v[ind].l - y - 1) / (p.first) + 1; ans += min(r, p.second); y += min(r, p.second) * p.first; p.second -= min(r, p.second); if (p.second != 0) q.push(p); } cout << -1 << endl; return 0; }