This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 17;
int f[N], a[N], n, u, v;
long long ans, s[N];
bool check (long long a, long long b, long long c)
{
    return (a | b) < (b | c);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> u >> v;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    for (int i = 40; i >= 0; --i)
    {
        long long x = 1LL << i;
        for (int j = 1; j <= n; ++j)
        {
            f[j] = n + 1;
            for (int k = 0; k < j; ++k)
            {
                if (check (s[j] - s[k], ans, x))
                {
                    f[j] = min (f[j], f[k] + 1);
                }
            }
        }
        if (f[n] > v)
        {
            ans += x;
        }
    }
    cout << ans;
}
| # | 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... |