题解:CF2118C Make It Beautiful
首先只有把一个数二进制表示下某一位的
考场上看到要求每个数最低位的
但是
把
CODE
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 5e+3 + 3;
int T, n, k, ans;
int lowbit(int x)
{
x = ~x;
return x & -x;
}
struct node
{
int w;
friend bool operator < (const node &x, const node &y)
{
return lowbit(x.w) > lowbit(y.w);
}
};
priority_queue<node> q;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--)
{
while (q.size())
{
q.pop();
}
cin >> n >> k;
ans = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
ans += __popcount(x);
q.push({x});
}
while (k)
{
int now = q.top().w;
q.pop();
int nd = lowbit(now);
if (k < nd)
{
break;
}
k -= nd;
ans++;
now += nd;
q.push({now});
}
cout << ans << '\n';
}
return 0;
}