fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define nl "\n"
  4. #define all(v) v.begin(),v.end()
  5. #define baraa ios_base::sync_with_stdio(false);cin.tie(NULL);
  6. using namespace std;
  7.  
  8. int main() {
  9. baraa
  10. ll t;
  11. cin >> t;
  12. while (t--) {
  13. ll n, k;
  14. cin >> n >> k;
  15. vector<ll> a(n);
  16. for (ll &i: a)cin >> i;
  17. for (ll bit = 0; bit < 61; bit++) {
  18. for (ll i = 0; i < n; i++) {
  19. if (a[i] >> bit & 1)continue;
  20. ll tar = a[i] | (1LL << bit);
  21. if (k - (tar - a[i]) >= 0)
  22. k -= (tar - a[i]), a[i] ^= (1LL << bit);
  23. }
  24. }
  25. ll res = 0;
  26. for (ll i: a)res += __builtin_popcountll(i);
  27. cout << res << nl;
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
91