#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9, N = 1e3 + 10;
long long n, a, b, c[N], v[N];
void input() {
cin >> n >> a >> b;
for (long long i = 1; i <= n; i++)
cin >> c[i];
}
void solve() {
long long ans = (1LL << 60) - 1;
for (long long i = 1; i <= n; i++)
v[i] = v[i - 1] + c[i];
for (long long j = 59; j >= 0; j--){
ans -= (1LL << j);
vector<pair<long long,long long>> dp(n + 1, {inf, -inf});
dp[0] = {0, 0};
for (long long i = 1; i <= n; i++){
for (long long k = 0; k < i; k++){
long long sum = v[i] - v[k];
if ((ans | sum) == ans && dp[k].first != inf){
dp[i].first = min(dp[i].first, dp[k].first + 1);
dp[i].second = max(dp[i].second, dp[k].second + 1);
}
}
}
if (dp[n].first == inf || max(a, dp[n].first) > min(b, dp[n].second))
ans += (1LL << j);
}
cout << ans;
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
input();
solve();
}
# | 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... |