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 pb push_back
int dp[2][205][100010];
signed main()
{
int n, k;
cin >> n >> k;
int a[n];
int pref[n];
int prev=0;
for(int i=0; i< n; i++){
cin >> a[i];
pref[i]=prev+a[i];
prev=pref[i];
}
for(int j=1; j<=k; j++){
for(int i=0; i<n; i++){
for(int l=i; l>=j-1; l--){
int val = dp[0][j-1][l]+pref[l]*(pref[i]-pref[l]);
if(val>=dp[0][j][i]){
dp[0][j][i]=val;
dp[1][j][i]=l;
}
}
}
}
cout << dp[0][k][n-1] << '\n';
vector<int> con;
prev=n-1;
for(int i=k; i>0; i--){
con.pb(dp[1][i][prev]);
prev=con.back();
}
reverse(con.begin(), con.end());
for(int e : con)cout << e+1 << " ";
}
# | 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... |