#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,l,r;
ll a[2020];
//ll dp[111][111][111];
ll dp[2020][2020];
/*ll solve(ll i,ll last,ll k,ll sum){
//cout<<"call: "<<i<<' '<<last<<' '<<k<<' '<<sum<<endl;
if(i==n){
if(k>=l&&k<=r&&last==n)return 0;
return -2;
}
ll &ans=dp[i][last][k];
sum+=a[i];
if(ans!=-1)return ans;
ll ans1=solve(i+1,last,k,sum),ans2=solve(i+1,i+1,k+1,0);
if(ans1==-2&&ans2==-2)return ans=-2;
if(ans1==-2)return ans=ans2|sum;
if(ans2==-2)return ans=ans1;
return ans=min(ans1,ans2|sum);
}*/
ll pre[2020];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>l>>r;
for(ll i=1;i<=n;i++){
cin>>a[i];
}
for(ll i=1;i<=n;i++){
pre[i]=a[i]+pre[i-1];
}
//memset(dp,-1,sizeof dp);
//cout<<max(0ll,solve(0,0,0,0))<<endl;
for(ll i=1;i<=n;i++){
dp[i][1]=pre[i];
for(ll k=2;k<=i;k++){
dp[i][k]=1e17;
ll sum=0;
for(ll j=i;j>k-1;j--){
sum+=a[j];
dp[i][k]=min(dp[i][k],sum|dp[j-1][k-1]);
}
}
}
ll ans=1e17;
for(ll i=l;i<=r;i++){
ans=min(ans,dp[n][i]);
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |