// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define speedup cin.tie(0)->sync_with_stdio(0)
#define all(x) begin(x), end(x)
#define int long long
#define pb push_back
#define arr array
#define vc vector
const int N = 2e2 + 10;
static int dp[N][N];
inline void solve () {
int n, l, r; cin >> n >> l >> r;
vc<int> pf (n + 1, 0), a (n + 1, 0);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) pf[i] = pf[i - 1] + a[i];
auto good = [&](int mask) -> int {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int j = 1; j <= r; j++) {
for (int i = 1; i <= n; i++) {
for (int k = 0; k < i; k++) {
int sum = pf[i] - pf[k];
if (((sum | mask) == mask) && dp[j - 1][k]) {
dp[j][i] = 1;
break;
}
}
}
if (dp[j][n] && j >= l) return 1;
}
return 0;
};
int lgm = 60, ans = (1LL << lgm) - 1;
for (int bit = lgm - 1; bit >= 0; bit--) {
ans ^= (1LL << bit);
if (!good(ans)) ans ^= (1 << bit);
}
cout << ans << '\n';
}
signed main() {
speedup;
solve();
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |