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>
using namespace std;
const int N = 1e5 + 17;
int n, k, cut[217][N], z, as[N], c;
long long a[N], f[217][N], s[N], ans;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
// for (int i = 1; i <= n; ++i)
// {
// for (int j = 1; j <= k + 1; ++j)
// {
// f[j][i] = -1;
// }
// }
for (int i = 1; i < n; ++i)
{
for (int j = 2; j <= min (i + 1, k + 1); ++j)
{
for (int t = j - 2; t < i; ++t)
{
if (f[j][i] < f[j - 1][t] + (s[i] - s[t]) * (s[n] - s[i]))
{
f[j][i] = f[j - 1][t] + (s[i] - s[t]) * (s[n] - s[i]);
cut[j - 1][i] = t;
if (f[j][i] >= ans)
{
ans = f[j][i];
z = i;
}
}
}
}
}
cout << ans << "\n";
if (!z)
{
return 0;
}
as[++c] = z;
int x = cut[k][z];
while (x)
{
as[++c] = x;
x = cut[--k][x];
}
while (c--)
{
cout << as[c + 1] << " ";
}
}
# | 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... |