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;
#define int long long
#define ar array
#define db double
const int mxn=3002,INF=2e18;
int n,k;
int a[mxn];
int pref[mxn];
int dp[mxn][mxn];
int track[mxn][mxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("sequence.in","r",stdin);
// freopen("sequence.out","w",stdout);
cin>>n>>k;
for (int i=1;i<=n;i++)
{
cin>>a[i];
pref[i]=pref[i-1]+a[i];
}
int sum=pref[n];
for (int i=0; i<=n; i++)
for (int j=0; j<=k+1; j++) dp[i][j]=INF;
for (int i=1; i<=n; i++) dp[i][1]=pref[i]*pref[i];
for (int i=2;i<=n;i++)
{
for (int j=2;j<=k+1;j++)
{
for (int i2=1; i2<i; i2++)
{
int tmp=pref[i]-pref[i2];
if (dp[i][j]>dp[i2][j-1]+tmp*tmp)
{
dp[i][j]=dp[i2][j-1]+tmp*tmp;
track[i][j]=i2;
}
}
}
}
cout<<(sum*sum-dp[n][k+1])/2<<"\n";
stack<int> ans;
while(track[n][k+1])
{
n=track[n][k+1];
ans.push(n);
k--;
}
while(!ans.empty())
{
cout<<ans.top()<<" ";
ans.pop();
}
return 0;
}
# | 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... |