Submission #130100

#TimeUsernameProblemLanguageResultExecution timeMemory
130100mlyean00Split the sequence (APIO14_sequence)C++14
0 / 100
2066 ms2040 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<ll> pref(n + 1, 0); partial_sum(a.begin(), a.end(), pref.begin() + 1); vector<int> p(n - 1); iota(p.begin(), p.end(), 1); ll max_pts = 0; vector<int> v(k); do { ll pts = 0; set<int> s {0, n}; for (int i = 0; i < k; ++i) { int l = *prev(s.lower_bound(p[i])); int r = *s.lower_bound(p[i]); pts += (pref[p[i]] - pref[l]) * (pref[r] - pref[p[i]]); s.insert(p[i]); } if (pts > max_pts) { max_pts = pts; copy(p.begin(), p.begin() + k, v.begin()); } } while (next_permutation(p.begin(), p.end())); cout << max_pts << endl; for (int i : v) { cout << i << ' '; } cout << endl; return 0; }
#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...