#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
#define N 300005
#define pii pair<int, int>
#define piii pair<int, pii>
using namespace std;
int n, k, i, j, a[N], t, mx, f[N], p[N], s[N], b, ans;
main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(i = 0; i < n; i++)
cin >> a[i];
while(k--)
{
t = mx = 0;
for(i = 0; i < n; i++)
{
if(f[i]) t = 0;
t += a[i];
p[i] = t;
}
t = 0;
for(i = n - 1; i >= 0; i--)
{
t += a[i];
s[i] = t;
if(f[i]) t = 0;
}
for(i = 0; i < n - 1; i++)
if(!f[i + 1] && p[i] * s[i + 1] >= mx) mx = p[i] * s[i + 1], b = i + 1;
f[b] = 1, ans += mx;
//cout << b << ' ' << mx << '\n';
}
cout << ans << '\n';
for(i = 0; i < n; i++)
if(f[i]) cout << i << ' ';
cout << '\n';
}
Compilation message
sequence.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Incorrect |
0 ms |
340 KB |
contestant didn't find the optimal answer: 951 < 999 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
contestant didn't find the optimal answer: 1093726 < 1093956 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
0 ms |
340 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
1 ms |
340 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
0 ms |
340 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
1 ms |
340 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Correct |
1 ms |
340 KB |
contestant found the optimal answer: 107630884 == 107630884 |
7 |
Correct |
1 ms |
340 KB |
contestant found the optimal answer: 475357671774 == 475357671774 |
8 |
Incorrect |
1 ms |
340 KB |
contestant didn't find the optimal answer: 193235243 < 193556962 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
contestant didn't find the optimal answer: 21419072 < 21503404 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
contestant didn't find the optimal answer: 1794250000 < 1818678304 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2644 KB |
contestant found the optimal answer: 19795776960 == 19795776960 |
2 |
Incorrect |
6 ms |
2644 KB |
contestant didn't find the optimal answer: 19874432171 < 19874432173 |
3 |
Halted |
0 ms |
0 KB |
- |