Submission #1059868

#TimeUsernameProblemLanguageResultExecution timeMemory
1059868vjudge1Split the sequence (APIO14_sequence)C++17
28 / 100
2075 ms131072 KiB
/**
 *                       \`*-.
 *                        )  _`-.
 *                       .  : `. .
 *                       : _   '  \
 *                       ; *` _.   `*-._
 *                       `-.-'          `-.
 *                         ;       `       `.
 *                         :.       .        \
 *                         . \  .   :   .-'   .
 *                         '  `+.;  ;  '      :
 *                         :  '  |    ;       ;-.
 *                         ; '   : :`-:     _.`* ;
 *          [VĐ]        .*' /  .*' ; .*`- +'  `*'
 *                      `*-*   `*-*  `*-*'
**/
/** HELLO WOLRD**/
#include <bits/stdc++.h>

#define NAME "main"
#define data DANG
#define ii pair<int64_t , int64_t>
#define fi first
#define se second

using namespace std;

const int64_t INF64 = 0x3f3f3f3f3f3f3f3f;
const int INF32 = 0x3f3f3f3f;
const int N = 1e5;

int n , m;
int64_t a[N + 2] , pre[N + 2] , dp[N + 2][205];
int64_t ans;
int trace[N + 2][205];

void init(){
    cin >> n >> m;

    for(int i = 1 ; i <= n ; i++)
        cin >> a[i];
}

void solve(){
    for(int i = 1 ; i <= n ; i++)
        pre[i] = pre[i - 1] + a[i];

    for(int i = 0 ; i <= n ; i++)
        for(int j = i + 1 ; j <= n ; j++)
            for(int k = 1 ; k <= m ; k++){
                int64_t tmp = dp[i][k - 1] + (pre[j] - pre[i]) * (pre[n] - pre[j]);
                if(tmp > dp[j][k]){
                    dp[j][k] = tmp;
                    trace[j][k] = i;
                }
            }

    int tr;

    for(int i = 1 ; i <= n ; i++)
        if(dp[i][m] > ans) ans = dp[i][m] , tr = i;

    cout << ans << '\n';
    vector<int> res;

    for(int i = m ; i >= 1 ; i--){
        res.push_back(tr);
        tr = trace[tr][i];
    }

    reverse(res.begin() , res.end());

    for(int x : res) cout << x << " ";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    init();
    solve();
}
#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...