#include #include #include #include #include #include #include using namespace std; vector> napok(30); int ketto_hatvany[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912 }; void magic(int band, int temp) { for (int i = 29; i >= 0; i--) { if (temp >= ketto_hatvany[i]) { temp -= ketto_hatvany[i]; napok[i].push_back(band); } } } int n, k; vector aktual; vector aktual2; int main() { cin >> n >> k; int temp; for (int i = 0; i < n; i++) { scanf("%d", &temp); magic(i, temp); } /* for (int i = 0; i < 30; i++) { for (int j = 0; j < melyik_nap_meret[i]; j++) { cout << melyik_nap_mennyi[i][j] << " "; } cout << endl; } */ int result = 0; int index_ = 0; for (int i = 29; i >= 0; i--) { if (napok[i].size() >= k) { aktual = napok[i]; result += ketto_hatvany[i]; index_ = i; break; } } for (int i = index_ - 1; i >= 0; i--) { aktual2 = napok[i]; vector res; std::set_intersection(aktual.begin(), aktual.end(), aktual2.begin(), aktual2.end(), std::back_inserter(res)); if (res.size() >= k) { aktual = res; result += ketto_hatvany[i]; } } cout << result << endl; return 0; }