#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 |
1 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Incorrect |
1 ms |
364 KB |
contestant didn't find the optimal answer: 954 < 999 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer 50 violates the range [1, 49] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer 201 violates the range [1, 199] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer 1000 violates the range [1, 999] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
492 KB |
contestant didn't find the optimal answer: 1788154876 < 1818678304 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2028 KB |
contestant found the optimal answer: 19795776960 == 19795776960 |
2 |
Incorrect |
21 ms |
2048 KB |
contestant didn't find the optimal answer: 19874432172 < 19874432173 |
3 |
Halted |
0 ms |
0 KB |
- |