#include #include #include #include using namespace std; int main() { int n; long long y, z; cin >> n >> y >> z; vector>> lxc(n); for (int i = 0; i < n; ++i) { long long c, l, x; cin >> c >> l >> x; lxc[i] = {l, {x, c}}; } sort(lxc.begin(), lxc.end()); int nowid = 0; long long ans = 0; priority_queue> pq; while (true) { while (nowid < n && lxc[nowid].first <= y) { pq.push(lxc[nowid].second); ++nowid; } long long ny = z; if (nowid < n) ny = min(ny, lxc[nowid].first); while (y < ny && !pq.empty()) { long long nok = ny - y; auto [x, c] = pq.top(); pq.pop(); long long cnt = min((nok + x - 1) / x, c); y += cnt * x; ans += cnt; c -= cnt; if (c > 0) pq.push({x, c}); } if (y >= z) break; if (y < ny) { ans = -1; break; } } cout << ans << endl; }