This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
7 3
4 1 3 4 0 2 3
**/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <assert.h>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <math.h>
#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define int long long
#define all(s) s.begin(), s.end()
#define ok puts("ok");
using namespace std;
const int N = 1e4 + 5;
const int inf = 1e18 + 7;
int n, k, ar[N], pref[N], dp[209][N], pr[209][N], last = 1, cur = 1;
main(){
cin >> n >> k;
for( int i = 1; i <= n; i++ ){
cin >> ar[i];
pref[ i ] = pref[ i - 1 ] + ar[ i ];
}
k++;
for( int i = 1; i <= k; i++ ){
last = 1;
cur = 1;
for( int j = 1; j <= n; j++ ){
for( int kk = last; kk <= j;kk++ ){
if( dp[ i ][ j ] <= dp[ i - 1 ][ kk - 1 ] + ( pref[ j ] - pref[ kk - 1 ] ) * ( pref[ n ] - pref[j] ) ){
dp[ i ][ j ] = max( dp[ i ][ j ], dp[ i - 1 ][ kk - 1 ] + (pref[j] - pref[kk - 1]) * (pref[n] - pref[j]) );
pr[ i ][ j ] = kk - 1;
cur = kk;
}
}
last = cur;
}
}
cout << dp[ k ][ n ] << endl;
while( k > 1 ){
cout << pr[ k ][ n ] << ' ';
n = pr[ k ][ n ];
k--;
}
}
Compilation message (stderr)
sequence.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |