#include using namespace std; using ll = long long; bool comp(tuple p,tuple q){ ll pa,pb,qa,qb; tie(pb,pa,ignore,ignore) = p; tie(qb,qa,ignore,ignore) = q; if(pb != qb)return pb < qb; return pa > pb; } int main(){ ll n,p,q; cin >> n >> p >> q; vector> t; for(ll i = 0;i> x >> a >> b; t.emplace_back(b,a,x,i); } vector> ans(n); sort(t.begin(),t.end(),comp); for(auto tup : t){ auto[b,a,x,i] = tup; ll used = min({x,a,p}); p -= used; x -= used; ans[i].first = used; ll t2; if(0