# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498426 | Ziel | Split the sequence (APIO14_sequence) | C++17 | 10 ms | 6604 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.
/**
* LES GREATEABLES BRO TEAM
**/
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");
#define int ll
const ll INF = 1e17+456;
int n, k;
ll dp[210][100013], a[100013], p[100013], last[210][100013];
void solve() {
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 <= n; i++) {
dp[1][i] = p[n] * p[i] - p[i] * p[i];
last[1][i] = i;
}
for (int j = 2; j <= k; j++) {
for (int i = n - 1; i >= 1; i--) {
if (dp[j][i + 1] < dp[j - 1][i + 1] + p[last[j - 1][i + 1]] * p[i] - p[i] * p[i] && i < last[j - 1][i + 1]) {
dp[j][i] = dp[j - 1][i + 1] + p[last[j - 1][i + 1]] * p[i] - p[i] * p[i];
last[j][i] = i;
} else {
dp[j][i] = dp[j][i + 1];
last[j][i] = last[j][i + 1];
}
}
}
cout << dp[k][1] << '\n';
{
int j = k, i = 1;
while (true) {
if (j < 1 || i > n)
break;
if (dp[j][i] == dp[j][i + 1])
i++;
else {
cout << i << ' ';
i++;
j--;
}
}
}
}
signed main() {
setIO();
int tt = 1;
if (FLAG) {
cin >> tt;
}
while (tt--) {
solve();
}
return 0;
}
void setIO(const string &f) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen((f + ".in").c_str(), "r")) {
freopen((f + ".in").c_str(), "r", stdin);
freopen((f + ".out").c_str(), "w", stdout);
}
}
Compilation message (stderr)
# | 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... |