multiset<pii,greater<pii> > nums; int ans[1001000]; int onenum(int x) { int res = 0; int now = 1; while(x-now > 0) { res ++; now <<= 1; } return res; } void solve() { int n,k; cin>>n>>k; for(int i = 1; i <= n; i ++) nums.insert({onenum(i),i}); int l = 1,r = n; for(int i = n; i >= 1; i --) { pii it = *nums.begin(); if(k >= it.x) { ans[r --] = it.y; k -= it.x; } else ans[l ++] = it.y; nums.erase(nums.begin()); } if(k) { cout<<-1<<endl; return; } for(int i = 1; i <= n; i ++) cout<<ans[i]<<' '; cout<<endl; return; }
全部评论
(1) 回帖