#include using namespace std; int main(){ using ll=long long; ll n,y,z; cin>>n>>y>>z; priority_queue> q; q.push({-z,0,0}); for (int i=0;i>c>>l>>x; q.push({-l,c,x}); } priority_queue> q2; ll ans=0; while (y(q.top())<=y){ auto [l,c,x]=q.top(); q.pop(); q2.push({x,c}); } ll r=-get<0>(q.top())-y; while (!q2.empty()&&r>0){ auto [x,c]=q2.top(); q2.pop(); ll q=min((r+x-1)/x,c); ans+=q; c-=q; y+=q*x; r-=q*x; if (c>0) q2.push({x,c}); } if (r>0){ cout<<-1<