Submission #541683

#TimeUsernameProblemLanguageResultExecution timeMemory
541683Aldas25Split the sequence (APIO14_sequence)C++14
28 / 100
2081 ms5136 KiB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 100100;
const ll INF = 1e16;

ll dp[210][MAXN];
int pr[210][MAXN];
int n, k;
ll a[MAXN], pref[MAXN];

int main()
{
    FAST_IO;

    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) pref[i] = pref[i-1] + a[i];

    dp[0][0] = 0;
    FOR(i, 1, n) dp[0][i] = -INF;

    FOR(g, 1, k+1) FOR(i, 1, n) FOR(j, 0, i-1) {
        ll k = pref[j];
        ll b = dp[g-1][j] - pref[j] * pref[j];
        ll x = pref[i];
        ll cr = k*x + b;
        if (cr > dp[g][i]) {
            dp[g][i] = k * x + b;
            pr[g][i] = j;
        }
    }

    cout << dp[k+1][n] << "\n";
    int g = k+1, i = n;
    while (g > 0) {
        i = pr[g][i];
        g--;
        if (i > 0) cout << i << " ";
    }
    cout << "\n";

    return 0;
}

/*

7 3
4 1 3 4 0 2 3

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...