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 all(x) (x).begin(), (x).end()
#define ll long long int
#define pb push_back
const int N = 10005;
int n, k, par[N][202];
ll pref[N], dp[N][202];
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
pref[i] = pref[i-1]+x;
}
for (int i = 2; i <= n; i++){
for (int x = 1; x <= k; x++){
for (int j = 1; j < i; j++){
ll cur = dp[j][x-1]+(pref[i]-pref[j])*pref[j];
if (dp[i][x] <= cur){
dp[i][x] = cur;
par[i][x] = j;
}
}
}
}
cout << dp[n][k] << '\n';
int cur = 0;
while(1){
n = par[n][k-cur++];
if(!n)break;
cout << n << ' ';
}
}
# | 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... |