Submission #922415

#TimeUsernameProblemLanguageResultExecution timeMemory
922415HiepVu217Split the sequence (APIO14_sequence)C++17
39 / 100
2100 ms89228 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 17; int n, k, cut[217][N], z, as[N], c; long long a[N], f[217][N], s[N], ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } for (int i = 1; i < n; ++i) { for (int j = 2; j <= min (i + 1, k + 1); ++j) { for (int t = j - 2; t < i; ++t) { if (f[j][i] < f[j - 1][t] + (s[i] - s[t]) * (s[n] - s[i])) { f[j][i] = f[j - 1][t] + (s[i] - s[t]) * (s[n] - s[i]); cut[j - 1][i] = t; if (f[j][i] >= ans) { ans = f[j][i]; z = i; } } } } } cout << ans << "\n"; if (!z) { return 0; } as[++c] = z; int x = cut[k][z]; while (x) { as[++c] = x; x = cut[--k][x]; } while (c--) { cout << as[c + 1] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...