# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499643 | pragmatist | Split the sequence (APIO14_sequence) | C++17 | 0 ms | 0 KiB |
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>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)1e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, c, a[N], p[N], dp[201][201];
pii pr[201][201];
void solve() {
cin >> n >> c;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
for(int i = 1; i <= n; ++i) {
for(int k = 1; k <= min(c, i); ++k) {
for(int j = 0; j < i; ++j) {
int cur = dp[j][k-1] + (p[i] - p[j]) * (p[n] - p[i]);
if(cur >= dp[i][k]) {
dp[i][k] = cur;
pr[i][k] = {j, k - 1};
}
}
}
}
int ans = 0, s = 0;
for(int i = 1; i <= n; ++i) {
if(dp[i][c] > ans) {
ans = dp[i][c];
s = i;
}
}
vector<int> v;
for(int t = c; t >= 1; --t) {
v.pb(s);
s = pr[s][t].x;
}
reverse(all(s));
cout << ans << nl;
for(auto x : v) cout << x << ' ';
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}