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 ll = long long;
using namespace std;
const int N = 111;
int n, k, a[N], sum[N], con = 0;
vector <int> ans;
int get(int l, int r) {
return sum[r] - sum[l - 1];
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
ans.push_back(n);
while (k--) {
int p = 1, mx = 0, res;
for (int i = 0; i < (int)ans.size(); ++i) {
for (int j = p; j < ans[i]; ++j) {
int tmp = get(p, j) * get(j + 1, ans[i]);
if (mx < tmp) {
mx = tmp;
res = j;
}
}
p = ans[i] + 1;
}
con += mx;
ans.push_back(res);
sort(ans.begin(), ans.end());
}
cout << con << '\n';
for (auto x : ans) {
if (x == n) {
break;
}
cout << x << ' ';
}
}
# | 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... |