#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> pref(n + 1, 0);
partial_sum(a.begin(), a.end(), pref.begin() + 1);
vector<int> p(n - 1);
iota(p.begin(), p.end(), 1);
ll max_pts = 0;
vector<int> v(k);
do {
ll pts = 0;
set<int> s {0, n};
for (int i = 0; i < k; ++i) {
int l = *prev(s.lower_bound(p[i]));
int r = *s.lower_bound(p[i]);
pts += (pref[p[i]] - pref[l]) * (pref[r] - pref[p[i]]);
s.insert(p[i]);
}
if (pts > max_pts) {
max_pts = pts;
copy(p.begin(), p.begin() + k, v.begin());
}
} while (next_permutation(p.begin(), p.end()));
cout << max_pts << endl;
for (int i : v) {
cout << i << ' ';
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
98 ms |
376 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
2 ms |
376 KB |
Integer 0 violates the range [1, 1] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2052 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2027 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2031 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2052 ms |
504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
2040 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |