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