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>
#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 (stderr)
sequence.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main()
| ^~~~
# | 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... |