#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
using namespace std;
pair<int, int> f(int l, int r, vector<int> &arr) {
if (r == l) {
return {0, l};
}
vector<int> keku = {arr[l]};
for (int i = l + 1; i <= r; i++) {
keku.push_back(keku.back() + arr[i]);
}
pair<int, int> ans = {0, l};
for (int i = l; i < r; i++) {
int now = keku[i - l] * (keku.back() - keku[i - l]);
ans = max(ans, make_pair(now, i));
}
return ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int &el : a) {
cin >> el;
}
set<pair<pair<int, int>, pair<int, int>>> heap;
heap.insert({f(0, n - 1, a), {0, n - 1}});
int ans = 0;
vector<int> res;
while (k--) {
auto lol = *--heap.end();
heap.erase(lol);
int val = lol.first.first, ind = lol.first.second, l = lol.second.first, r = lol.second.second;
ans += val;
res.push_back(ind + 1);
heap.insert({f(l, ind, a), {l, ind}});
heap.insert({f(ind + 1, r, a), {ind + 1, r}});
}
cout << ans << '\n';
for (int el : res) {
cout << el << ' ';
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Incorrect |
1 ms |
492 KB |
contestant didn't find the optimal answer: 951 < 999 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
contestant didn't find the optimal answer: 1093726 < 1093956 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Incorrect |
1 ms |
364 KB |
Integer 200 violates the range [1, 199] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
contestant didn't find the optimal answer: 21419072 < 21503404 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
668 KB |
contestant didn't find the optimal answer: 1794250000 < 1818678304 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
2540 KB |
contestant found the optimal answer: 19795776960 == 19795776960 |
2 |
Incorrect |
11 ms |
2668 KB |
contestant didn't find the optimal answer: 19874432171 < 19874432173 |
3 |
Halted |
0 ms |
0 KB |
- |