This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #define _GLIBCXX_DEBUG
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <random>
#include <queue>
#include <bitset>
#define int long long
#define dbl long double
#define pb push_back
#define str string
using namespace std;
const int M = 998244353;
int dp[100009][209];
int par[100009][209];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) cin >> A[n + 1 - i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
dp[i][j] = -1e18;
}
}
vector<int> pref = A;
for (int i = 1; i <= n; i++) pref[i] += pref[i - 1];
for (int t = 1; t <= k; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (dp[i][t] < dp[j][t - 1] + pref[j] * (pref[i] - pref[j])) {
par[i][t] = j;
dp[i][t] = dp[j][t - 1] + pref[j] * (pref[i] - pref[j]);
}
}
}
}
cout << dp[n][k] << '\n';
int i = n;
int t = k;
vector<int> ans;
while (t--) {
ans.pb(n - 1 - par[i][t]);
i = par[i][t];
}
for (auto p : ans) cout << p << ' ';
}
# | 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... |