# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951263 | Nelt | Split the sequence (APIO14_sequence) | C++17 | 0 ms | 0 KiB |
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 ll long long
#define endl "\n"
using namespace std;
ll intersection(ll k, ll b, ll k1, ll b1)
{
if (k == k1)
return -1;
return (ll)((b1 - b) / (k - k1 + 0.0));
}
void solve()
{
ll n, k;
cin >> n >> k;
ll dp[2][n + 1], a[n + 1];
int best[k + 1][n + 1];
for (ll i = 0; i <= k; i++)
for (ll j = 0; j <= n; j++)
best[i][j] = 0;
a[0] = 0;
for (ll i = 1; i <= n; i++)
cin >> a[i], a[i] += a[i - 1];
for (ll i = 0; i <= n; i++)
dp[0][i] = 0, dp[1][i] = -1e18;
vector<array<ll, 3>> v;
for (ll i = 1; i <= k; i++)
{
v.clear();
for (ll j = 0; j <= n; j++)
{
while (!v.empty() and v.back()[0] *
}
// for (ll j = 1; j <= n; j++)
// dp[i & 1][j] = max(dp[(i + 1) & 1][m] + (a[j] - a[m]) * (a[n] - a[j]), dp[i & 1][j]);
}
ll ans = 0;
for (ll i = 1; i < n; i++)
ans = max(ans, dp[k & 1][i]);
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
// precomp();
// cin >> t;
for (ll i = 1; i <= t; i++)
solve();
cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}