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>
#define ll long long
using namespace std;
ll n,k,i,j,l,a[100001],dp[201][100001],sum[100001],s,ans;
vector<ll> v;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
for(i=1;i<=n;i++){
cin >> a[i];
sum[i]=sum[i-1]+a[i];
}
for(l=1;l<=k;l++){
for(i=l;i<=n;i++){
for(j=l-1;j<i;j++){
dp[l][i]=max(dp[l][i],dp[l-1][j]+(sum[n]-sum[i])*(sum[i]-sum[j]));
}
}
}
for(i=k;i<=n;i++) ans=max(ans,dp[k][i]);
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |