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 ll long long
#define pb push_back
const int maxn = 2e2 + 20;
const int maxk = 2e2 + 20;
int par[maxn][maxk] , sum[maxn];
ll dp[maxn][maxk];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n , k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> sum[i] , sum[i] += sum[i - 1];
memset(dp , 63 , sizeof dp);
dp[0][0] = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
for(int x = 0; x < i; x++)
dp[i][j] = min(dp[i][j] , (sum[i] - sum[x]) * (sum[i] - sum[x]) + dp[x][j - 1]);
for(int x = 0; x < i; x++)
if((sum[i] - sum[x]) * (sum[i] - sum[x]) + dp[x][j - 1] == dp[i][j])
par[i][j] = x;
}
int A = n;
vector<int> ans;
for(int j = k + 1; j > 1; j--)
{
ans.pb(par[A][j]);
A = par[A][j];
}
reverse(ans.begin() , ans.end());
cout << (1LL * (sum[n] * sum[n]) - dp[n][k + 1]) / 2 << endl;
for(auto x : ans)
cout << x << " ";
cout << endl;
}
# | 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... |