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;
int n,k,a[100005],f[100005][205],Trace[100005][205];
vector<int> rs;
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n>>k;
k++;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=0;i<=n;i++)
for(int j=0;j<=k;j++)
f[i][j]=-1;
f[0][0]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)
for(int t=1;t<=i;t++)
if(f[t-1][j-1]!=-1&&f[i][j]<f[t-1][j-1]+(a[i]-a[t-1])*a[t-1])
{
f[i][j]=f[t-1][j-1]+(a[i]-a[t-1])*a[t-1];
Trace[i][j]=t-1;
}
cout<<f[n][k]<<"\n";
while(k>1)
{
rs.push_back(Trace[n][k]);
n=Trace[n][k];
k--;
}
for(int i=rs.size()-1;i>=0;i--)
cout<<rs[i]<<' ';
}
# | 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... |