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;
#define int long long
signed main() {
int n, k, mx = 0, sm;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (i) a[i] += a[i - 1];
}
vector<int> ans, vec;
for (int i = 1; i <= k; ++i) vec.emplace_back(i);
while (true) {
sm = 0;
for (int i = 0; i < k; ++i) {
if (i) sm += (a[vec[i] - 1] - a[vec[i - 1] - 1]) * (a[n - 1] - a[vec[i] - 1]);
else sm += a[vec[i] - 1] * (a[n - 1] - a[vec[i] - 1]);
}
if (sm > mx) ans = vec, mx = sm;
vec[k - 1]++;
for (int i = k - 1; i > 0; --i) if (vec[i] > n - k + i + 1) vec[i - 1]++, vec[i] = i + 1;
if (vec[0] > n - k + 1) break;
}
cout << mx << '\n';
for (int i : ans) cout << i << ' ';
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... |