#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
#define INF 1e18
int dp[2001][2001];
void solve() {
int n, l, r; cin >> n >> l >> r;
vll a(n);
for(auto& x : a) cin >> x;
const int K = 45;
ll cand = 0;
auto f = [&](int b) -> bool {
memset(dp, -1, sizeof(dp));
auto dfs = [&](auto& dfs, int i = 0, int g = 0) -> int {
if(i == n) return l <= g && g <= r;
if(g >= r) return false;
auto& res = dp[i][g];
if(res != -1) return res;
ll x = 0;
for(int j = i; j < n; j++) {
x += a[j];
if((cand >> b) == ((cand | x) >> b)) {
if(dfs(dfs, j + 1, g + 1)) return res = 1;
}
}
return res = 0;
};
return dfs(dfs);
};
for(int b = K - 1; b >= 0; b--) {
if(f(b)) continue;
cand ^= 1LL << b;
}
cout << cand << '\n';
}
signed main() {
int t = 1;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# | 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... |