이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = lower_bound(pr.begin(), pr.end(), needsum + cursum) - pr.begin();
//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... |