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;
long long dp[1001][202]={},n,k,arr[1001]={};
void solve(long x)
{
if(x==n){
return;
}
for(long i=0;i<x;i++){
for(long j=1;j<=k;j++){
dp[x][j+1]=max(dp[x][j+1],dp[i][j]+((arr[n-1]-arr[x])*(arr[x]-arr[i])));
}
}
solve(x+1);
}
int main()
{
long long x;
cin>>n>>k;
cin>>x;
arr[0]=x;
for(long i=1;i<n;i++){
cin>>x;
arr[i]=arr[i-1]+x;
}
for(long i=0;i<n;i++){
dp[i][1]=arr[i]*(arr[n-1]-arr[i]);
}
solve(1);
cout<<dp[n-1][k+1]<<endl;
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... |