Submission #163990

#TimeUsernameProblemLanguageResultExecution timeMemory
163990tunaSplit the sequence (APIO14_sequence)C++11
0 / 100
2 ms504 KiB
#include "bits/stdc++.h" using ll = long long; using namespace std; const int N = 111; int n, k, a[N], sum[N], con = 0; vector <int> ans; int get(int l, int r) { return sum[r] - sum[l - 1]; } int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } ans.push_back(n); while (k--) { int p = 1, mx = 0, res; for (int i = 0; i < (int)ans.size(); ++i) { for (int j = p; j < ans[i]; ++j) { int tmp = get(p, j) * get(j + 1, ans[i]); if (mx < tmp) { mx = tmp; res = j; } } p = ans[i] + 1; } con += mx; ans.push_back(res); sort(ans.begin(), ans.end()); } cout << con << '\n'; for (auto x : ans) { if (x == n) { break; } cout << x << ' '; } }
#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...