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;
int64_t n,k,a[100005],f[1005][205],Trace[1005][205];
void Sub1()
{
for(int64_t i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
for(int64_t i=0;i<=n;i++)
for(int64_t j=0;j<=k;j++)
f[i][j]=-1;
f[0][0]=0;
for(int64_t i=1;i<=n;i++)
for(int64_t j=1;j<=k;j++)
for(int64_t 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)
{
cout<<Trace[n][k]<<' ';
n=Trace[n][k];
k--;
}
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n>>k;
k++;
if(n<=1000)
Sub1();
}
# | 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... |