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 <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 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... |