제출 #562808

#제출 시각아이디문제언어결과실행 시간메모리
562808Ooops_sorrySplit the sequence (APIO14_sequence)C++14
50 / 100
2067 ms24788 KiB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld long double
#define ll long long

mt19937 rnd(51);

const ll INF = 1e18;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LCOAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n), pr(n);
    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, -INF));
    vector<vector<int>> par(n + 1, vector<int>(k + 1));
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        pr[i] = a[i];
        if (i > 0) {
            pr[i] += pr[i - 1];
        }
    }
    for (int i = 0; i < n; i++) {
        dp[i][0] = 0;
        for (int f = 0; f < k; f++) {
            ll sum = 0;
            for (int j = i + 1; j < n; j++) {
                sum += a[j];
                if (dp[i][f] + sum * pr[i] > dp[j][f + 1]) {
                    dp[j][f + 1] = dp[i][f] + sum * pr[i];
                    par[j][f + 1] = i;
                }
            }
        }
    }
    cout << dp[n - 1][k] << endl;
    vector<int> res;
    int i = n - 1, j = k, sum = 0;
    while (j > 0) {
        res.pb(i - par[i][j]);
        i = par[i][j];
        j--;
        sum += res.back();
    }
    int now = 0;
    for (auto to : res) {
        cout << (now += to) << ' ';
    }
    cout << endl;
    return 0;
}
#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...