Language: C++

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n, k;

int main() {
    cin >> n >> k;
    vector<ll> A(n, 0);
    ll MAX = k;
    for(int i = 0; i < n; ++i) {
        cin >> A.at(i);
        chmax(MAX, A.at(i));
    }

    vector<ll> bitcnt(64, 0);
    for(int i = 0; i < n; ++i) {
        ll j = 0;
        while((1LL<<j) <= A.at(i)) {
            if(A.at(i)&(1LL<<j)) {
                bitcnt.at(j)++;
            }
            j++;
        }
    }

    ll limit = 0;
    while((1LL<<limit) <= MAX) limit++;
    ll cc = 0;
    vector<ll> bitk;
    while((1LL<<cc) <= k) {
        if(k&(1LL<<cc)) {
            bitk.emplace_back(1);
        }else bitk.emplace_back(0);
        cc++;
    }

    // cout << "cc " << cc << endl;

    // limitが全体の01列の長さ、ccが01が選べる長さ、cc以上は必ず0を選択する

    vector<ll> ansvec1(limit, 0);
    // ansvec1はcc-1が1のときの最大
    for(int i = 0; i < limit; ++i) {
        ll cnt0 = n - bitcnt.at(i);
        ll cnt1 = bitcnt.at(i);
        if(i < cc) {
            if(bitk.at(i) == 1) {
                if(cnt0 >= cnt1) ansvec1.at(i) = 1;
                else ansvec1.at(i) = 0;
            }
        }else ansvec1.at(i) = 0;
    }

    vector<ll> ansvec0(limit, 0);
    // ansvec0はcc-1が0のときの最大
    for(int i = 0; i < limit; ++i) {
        ll cnt0 = n - bitcnt.at(i);
        ll cnt1 = bitcnt.at(i);
        if(i < max(0, cc-1)) {
            if(cnt0 >= cnt1) ansvec0.at(i) = 1;
            else ansvec0.at(i) = 0;
        }else ansvec0.at(i) = 0;
    }

    /*for(int i = 0; i < limit; ++i) {
        cout << ansvec0.at(i);
    }
    cout << endl;

    for(int i = 0; i < limit; ++i) {
        cout << ansvec1.at(i);
    }
    cout << endl;*/


    ll ans0 = 0;
    ll now0 = 1;
    for(int i = 0; i < limit; ++i) {
        if(ansvec0.at(i) == 1) {
            ans0 += (now0*(n-bitcnt.at(i)));
        }else {
            ans0 += (now0*bitcnt.at(i));
        }
        now0 *= 2;
    }

    ll ans1 = 0;
    ll now1 = 1;
    for(int i = 0; i < limit; ++i) {
        if(ansvec1.at(i) == 1) {
            ans1 += (now1*(n-bitcnt.at(i)));
        }else {
            ans1 += (now1*bitcnt.at(i));
        }
        now1 *= 2;
    }

    cout << max(ans0, ans1) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:19: error: no matching function for call to 'max(int, ll)'
   65 |         if(i < max(0, cc-1)) {
      |                ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:65:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   65 |         if(i < max(0, cc-1)) {
      |                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:65:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   65 |         if(i < max(0, cc-1)) {
      |                ~~~^~~~~~~~~