#include using namespace std; using ll = long long; bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; } bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N, Y, Z; cin >> N >> Y >> Z; vector> S(N); // (L, X, C) for (int i = 0; i < N; ++i) cin >> get<2>(S[i]) >> get<0>(S[i]) >> get<1>(S[i]); sort(S.begin(), S.end()); int s = 0; ll ans = 0; priority_queue> pq; for (; s < N && get<0>(S[s]) <= Y; ++s) { auto [l, x, c] = S[s]; pq.push({x, c}); } while (!pq.empty() && Y < Z) { // cout << s << ' ' << Y << ' ' << ans << '\n'; if (s == N) { while (!pq.empty()) { auto [x, c] = pq.top(); pq.pop(); ll beat = min((Z - Y + x - 1) / x /* ceil(Z-Y / x) */, c); ans += beat; Y += x * beat; if (Y >= Z) { cout << ans << '\n'; return 0; } } cout << -1 << '\n'; return 0; } while (!pq.empty() && Y < get<0>(S[s])) { auto [x, c] = pq.top(); pq.pop(); ll beat = min((get<0>(S[s]) - Y + x - 1) / x, c); ans += beat; Y += x * beat; if (beat < c) pq.push({x, c - beat}); } if (Y < get<0>(S[s])) { cout << -1 << '\n'; return 0; } for (; s < N && get<0>(S[s]) <= Y; ++s) { auto [l, x, c] = S[s]; pq.push({x, c}); } } if (Y >= Z) cout << ans << '\n'; else cout << -1 << '\n'; }