이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define ins insert
#define er erase
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int oo = 1e18 + 7, mod = 1e9 + 7;
const int N = 2e5 + 5, K = 205;
int n, k, a[N], suff[N];
ii dp[N][K];
signed main(){
ios_base::sync_with_stdio(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = n; i >= 1; i--) suff[i] = (suff[i + 1] + a[i]);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= min(i, k); j++){
for(int itr = i - 1; itr >= (j - 1); itr--) if(dp[i][j].fi < dp[itr][j - 1].fi + (suff[itr + 1] - suff[i + 1]) * suff[i + 1]) dp[i][j] = {dp[itr][j - 1].fi + (suff[itr + 1] - suff[i + 1]) * suff[i + 1], itr};
}
}
int ind = k;
for(int i = k + 1; i <= n; i++){
if(dp[i][k].fi > dp[ind][k].fi) ind = i;
}
cout << dp[ind][k].fi << "\n";
vector<int> pos;
pos.clear();
int tmp = k;
while(tmp){
pos.pb(ind);
ind = dp[ind][tmp].se;
tmp--;
}
for(int i = pos.size() - 1; i >= 0; i--) cout << pos[i] << " ";
}
# | 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... |