#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define dbg(x) cerr << #x << ": " << x << endl;
const int MAX_BIT = 44;
const int MAX_N = 2000 + 5;
const int MAX_X = 20;
int a[MAX_N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, l, r;
cin >> n >> l >> r;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
// minimize (a1 + a2 + ... + a_(k - 1)) | (a_k + a_(k + 1) + ...) | ...
// IMPORTANT NOTE: IN LAST GROUP n = 2000 and l = 1
// maybe greedy bit by bit? minimize first, then second, ...
auto check = [&](ll mask) {
int groups_n = 1;
ll curr_sum = 0;
for (int i = 1; i <= n; ++i) {
if (((curr_sum + a[i]) & mask) == 0) {
curr_sum += a[i];
} else {
curr_sum = a[i];
++groups_n;
}
}
return groups_n <= r;
};
ll ans = 0;
ll mask = 0;
for (int bit = MAX_BIT; bit >= 0; --bit) {
if (!check(mask | (1LL << bit))) {
ans |= 1LL << bit;
} else {
mask |= 1LL << bit;
}
}
cout << ans << '\n';
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |