이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl;
#define MP make_pair
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define ALL(x) x.begin(),x.end()
#define endl "\n"
const ll inf=1e18;
const ll maxn=11111;
ll dp[maxn][222];
ll a[maxn],pre[maxn];
pll fa[maxn][222];
void dfs(pll u){
if(u.fi==0)return;
dfs(fa[u.fi][u.se]);
cout<<u.fi<<" ";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll n,K;cin>>n>>K;
rep(i,1,n+1)cin>>a[i];
rep(i,1,n+1)pre[i]=pre[i-1]+a[i];
rep(k,1,K+1){
rep(i,1,n+1){
rep(j,0,i){
if(dp[j][k-1]+(pre[i]-pre[j])*(pre[n]-pre[i])>dp[i][k]){
dp[i][k]=dp[j][k-1]+(pre[i]-pre[j])*(pre[n]-pre[i]);
fa[i][k]=MP(j,k-1);
}
}
}
}
/*
rep(i,1,n+1){
rep(j,0,K+1)cout<<dp[i][j]<<" ";
cout<<endl;
}
*/
ll mx=-inf;
pll p=MP(0ll,0ll);
rep(i,1,n+1){
if(dp[i][K]>mx){
mx=dp[i][K];
p=MP(i,K);
}
}
cout<<mx<<endl;
dfs(p);
return 0;
}
# | 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... |