Submission #321054

#TimeUsernameProblemLanguageResultExecution timeMemory
321054shart23Split the sequence (APIO14_sequence)C++14
0 / 100
11 ms2668 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(), x.end() using namespace std; pair<int, int> f(int l, int r, vector<int> &arr) { if (r == l) { return {0, l}; } vector<int> keku = {arr[l]}; for (int i = l + 1; i <= r; i++) { keku.push_back(keku.back() + arr[i]); } pair<int, int> ans = {0, l}; for (int i = l; i < r; i++) { int now = keku[i - l] * (keku.back() - keku[i - l]); ans = max(ans, make_pair(now, i)); } return ans; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n); for (int &el : a) { cin >> el; } set<pair<pair<int, int>, pair<int, int>>> heap; heap.insert({f(0, n - 1, a), {0, n - 1}}); int ans = 0; vector<int> res; while (k--) { auto lol = *--heap.end(); heap.erase(lol); int val = lol.first.first, ind = lol.first.second, l = lol.second.first, r = lol.second.second; ans += val; res.push_back(ind + 1); heap.insert({f(l, ind, a), {l, ind}}); heap.insert({f(ind + 1, r, a), {ind + 1, r}}); } cout << ans << '\n'; for (int el : res) { cout << el << ' '; } cout << '\n'; }
#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...