# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863528 | SyedShajib | Split the sequence (APIO14_sequence) | C++17 | 2095 ms | 13400 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 <iostream>
#include <vector>
#include <algorithm>
int main() {
int n, k;
std::cin >> n >> k;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
std::vector<std::vector<long long>> dp(n + 1, std::vector<long long>(k + 1, -1));
std::vector<std::vector<int>> pos(n + 1, std::vector<int>(k + 1, -1));
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= k; ++j) {
if (dp[i][j] != -1) {
long long sum = 0;
for (int l = i; l < n; ++l) {
sum += a[l];
if (j + 1 <= k && dp[l + 1][j + 1] < dp[i][j] + sum * (l - i + 1)) {
dp[l + 1][j + 1] = dp[i][j] + sum * (l - i + 1);
pos[l + 1][j + 1] = i;
}
}
}
}
}
std::cout << dp[n][k] << std::endl;
int cur = n, curk = k;
std::vector<int> splits;
while (cur > 0) {
splits.push_back(pos[cur][curk]);
cur = pos[cur][curk];
--curk;
}
std::reverse(splits.begin(), splits.end());
for (int i = 0; i < splits.size() - 1; ++i) {
std::cout << splits[i] << ' ';
}
return 0;
}
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... |