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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> pr(n + 1);
for (int i = 0; i < n; ++i) pr[i + 1] = pr[i] + a[i];
int needsum = pr[n] / (k + 1);
int it = 0;
int cursum = 0;
int ans = 0;
vector<int> ans1;
for (int i = 0; i < k; ++i) {
int pos1 = upper_bound(pr.begin(), pr.end(), needsum + cursum) - pr.begin() - 1;
//cout << pr[pos1] << endl;
ans += ((pr[pos1] - pr[it]) * (pr[n] - pr[pos1]));
ans1.push_back(pos1);
it = pos1 ;
cursum = pr[pos1];
}
cout << ans << '\n';
for (auto elme : ans1) cout << elme << ' ';
}
# | 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... |