#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e3+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
vector<vector<int>> dp(MAXN, vector<int>(MAXN, inf));
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n,a,b;
cin >> n >> a >> b;
vector<int>niz(n);
vector<int>pref(n+1, 0);
for(int i=0; i<n; i++)
{
cin >> niz[i];
pref[i+1] = pref[i] + niz[i];
}
for(int i=0; i<n; i++)dp[1][i] = pref[i+1];
for(int i=2; i<=b; i++)
{
for(int j=i-1; j<n; j++)
{
for(int k=0; k<j; k++)
{
dp[i][j] = min(dp[i][j], dp[i-1][k]| (pref[j+1]- pref[k+1]));
}
}
}
int rez = inf;
for(int i=a; i<=b; i++)rez = min(rez, dp[i][n-1]);
cout << rez << endl;
}
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31832 KB |
Output is correct |
2 |
Incorrect |
23 ms |
31836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31836 KB |
Output is correct |
2 |
Incorrect |
15 ms |
31764 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31820 KB |
Output is correct |
2 |
Incorrect |
16 ms |
31836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31836 KB |
Output is correct |
2 |
Incorrect |
21 ms |
31848 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31832 KB |
Output is correct |
2 |
Incorrect |
16 ms |
31836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |