// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define now chrono::steady_clock::now().time_since_epoch().count()
#define speedup cin.tie(0)->sync_with_stdio(0)
#define bitcount(x) __builtin_popcountll(x)
#define lla(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define Tp template <class T>
#define int long long
#define pb push_back
#define vc vector
#define arr array
const int inf = 1e18, N = 1e3 + 10, K = 201;
Tp bool chmin (T &a, T b) {if (a > b) {a = b; return 1;} return 0;}
Tp bool chmax (T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
static int a[N], pf[N], dp[K][N], opt[K][N];
inline void solve () {
int n, kx;
cin >> n >> kx;
pf[0] = a[0] = 0;
if (n == 1) return cout << "0\n", void();
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) pf[i] = pf[i - 1] + a[i];
memset(dp, 0, sizeof(dp));
memset(opt, 0, sizeof(opt));
for (int i = 1; i <= kx; i++) {
for (int j = 2; j <= n; j++) {
for (int k = j - 1; k >= 1; k--) {
int val = dp[i - 1][k] + pf[k] * (pf[j] - pf[k]);
if (chmax(dp[i][j], val)) opt[i][j] = k;
}
}
}
int x = n;
vc<int> ans;
for (int i = kx; i >= 1; i--) {
x = opt[i][x];
ans.pb(x);
}
reverse(all(ans));
cout << dp[kx][n] << '\n';
for (int &x : ans) cout << x << ' ';
}
signed main() {
speedup;
solve();
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... |