#include using namespace std; #define rep(i, x, limit) for (long long i = (long long)x; i < (long long)limit; i++) #define REP(i, x, limit) for (long long i = (long long)x; i <= (long long)limit; i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define el '\n' #define spa " " #define Yes cout << "Yes" << el #define No cout << "No" << el #define YES cout << "YES" << el #define NO cout << "NO" << el #define eps (1e-10) #define Equals(a,b) (fabs((a) - (b)) < eps ) #define debug(x) cerr << #x << " = " << x << el using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; using vvl = vector>; using vs = vector; using vb = vector; const double pi = 3.141592653589793238; const int inf = 1073741823; const ll infl = 1LL << 60; const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string abc = "abcdefghijklmnopqrstuvwxyz"; const ll MOD = 998244353; #include using namespace atcoder; using mint = modint998244353; using vm = vector; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n,y,z;cin>>n>>y>>z; using T=tuple; priority_queue,greater> pq1; priority_queue pq2; rep(i,0,n){ ll c,l,x;cin>>c>>l>>x; pq1.push({l,x,c}); } ll ans=0; while (y < z) { while (!pq1.empty() && get<0>(pq1.top()) <= y) { auto [l, x, c] = pq1.top(); pq1.pop(); pq2.push({x, c}); } ll m = z; if (!pq1.empty()) m = min(get<0>(pq1.top()), z); while (y < m) { if (pq2.empty()) { cout << -1 << el; return 0; } auto [xx, cc] = pq2.top(); pq2.pop(); ll need = (m - y + xx - 1) / xx; if (cc < need) { ans += cc; y += xx * cc; } else { ans += need; y += xx * need; if (cc > need) pq2.push({xx, cc - need}); } } } cout<