This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* \`*-.
* ) _`-.
* . : `. .
* : _ ' \
* ; *` _. `*-._
* `-.-' `-.
* ; ` `.
* :. . \
* . \ . : .-' .
* ' `+.; ; ' :
* : ' | ; ;-.
* ; ' : :`-: _.`* ;
* [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';
if(ans == 0) return;
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 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... |