This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;
const int N = 111111;
const int K = 211;
int n, k;
int a[N], p[N], dp[K][N], pa[K][N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
for (int i = 1; i <= k; i++) {
for (int j = i; j <= n; j++) {
for (int l = 1; l < j; l++) {
if (dp[i][j] <= dp[i - 1][l] + (p[j] - p[l]) * p[l]) {
dp[i][j] = dp[i - 1][l] + (p[j] - p[l]) * p[l];
pa[i][j] = l;
}
}
}
}
cout << dp[k][n] << endl;
int x = pa[k][n];
while (k--) {
cout << x << " ";
x = pa[k][x];
}
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... |