rt。
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
unsigned long long n, m, K, ans, now, cost;
bool flag;
array<unsigned long long, 200001> a;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m >> K;
auto B(a.begin()), E(a.begin() + n), F(a.begin() + K);
for(auto i(B); i != E; ++ i)
cin >> *i;
sort(B, E, greater<unsigned long long>());
for(unsigned long long j(2147483648ull); j; j >>= 1ull)
{
now = cost = 0ull;
for(auto i(B); i != E; ++ i)
if(*i & j && now < K)
++ now;
else if(i < F)
cost -= *i;
cost += j * (K - now);
if(m >= cost)
{
m -= cost;
flag = true;
ans = j;
for(auto i(B); i != F; ++ i)
if(! (*i & j))
*i = 0ull;
}
else
flag = false;
for(auto i(B); i != E; ++ i)
{
*i |= j;
*i ^= j;
}
if(flag)
break;
sort(B, E, greater<unsigned long long>());
}
sort(B, F, greater<unsigned long long>());
for(unsigned long long j(ans >> 1u); j; j >>= 1ull)
{
now = cost = 0ull;
for(auto i(B); i != F; ++ i)
if(*i & j)
++ now;
else
cost -= *i;
cost += j * (K - now);
if(m >= cost)
{
m -= cost;
ans |= j;
for(auto i(B); i != F; ++ i)
if(! (*i & j))
*i = 0ull;
}
for(auto i(B); i != F; ++ i)
{
*i |= j;
*i ^= j;
}
sort(B, F, greater<unsigned long long>());
}
cout << ans;
return 0;
}