# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395788 | kaplanbar | Split the sequence (APIO14_sequence) | C++14 | 9 ms | 1868 KiB |
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() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<ll> v(n);
for(int i = 0; i < n; i++) cin >> v[i];
vector<ll> pre(n);
for(int i = 0; i < n; i++) {
pre[i] = v[i];
if(i) pre[i] += pre[i - 1];
}
auto get_sum = [&](int l, int r) -> ll {
ll ret = pre[r];
if(l) ret -= pre[l - 1];
return ret;
};
ll s = get_sum(0, n - 1);
ll ans = 0, cur = 0;
vector<int> a;
for(int i = 0; i < n; i++) {
cur += v[i];
if(cur >= s / (k + 1)) {
ans += cur * (s - cur);
a.push_back(i + 1);
cur = 0;
}
}
assert(a.size() == k + 1);
a.pop_back();
cout << ans / 2 << "\n";
for(int x : a) cout << x << " ";
return 0;
}
Compilation message (stderr)
# | 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... |