#include #include #include using namespace std; const int MAXN=10e+6; struct f { int ind,h,p; }; struct C1 { int cmp(f f1,f f2) const { if(f1.p>f2.p)return 1; if(f1.pf2.h)return -1; return f1.ind-f2.ind; } bool operator()(f f1,f f2) const { return cmp(f1,f2)<0; } }; vector> res; int n,b; f inp[MAXN]; set s_p; set s_h; int main() { freopen("sticks.in", "r", stdin); freopen("sticks.out", "w", stdout); cin>>n>>b; for(int i=0;i>inp[i].h; } for(int i=0;i>inp[i].p; s_p.insert(inp[i]); s_h.insert(inp[i]); } int k=0; while(s_p.size()>0) { if(k<=0) { res.push_back(vector()); k=b; } auto it=s_h.upper_bound(f{-1,k,-1}); f tmp; if(it!=s_h.end()) { tmp=*it; (*res.rbegin()).push_back(tmp.ind); s_h.erase(it); s_p.erase(tmp); } else { it=s_p.begin(); tmp=*it; (*res.rbegin()).push_back(tmp.ind); s_h.erase(tmp); s_p.erase(it); } k-=tmp.h; } cout<