이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
ll dp[201][1010]={},pre[1010][201];
int main(){
int n,k; cin>>n>>k;
if(n>1000)return 0;
vector<ll> a(n),rui(n+1);
rep(i,0,n){
cin>>a[i]; rui[i+1]=a[i];
}
rep(i,0,n)rui[i+1]+=rui[i];
rep(i,0,n+1)rep(j,0,k+1)dp[i][j]=-INF;
dp[0][0]=0;
rep(i,1,k+1)rep(j,1,n)rep(i2,0,j){
ll add=(rui[j]-rui[i2])*(rui[n]-rui[j]);
if(chmax(dp[i][j],dp[i-1][i2]+add))pre[i][j]=i2;
}
ll res=0; int pos=-1;
rep(i,0,n)if(chmax(res,dp[k][i]))pos=i;
cout<<res<<endl;
int cur=k; vector<int> ps;
while(cur){
ps.push_back(pos);
pos=pre[cur][pos]; cur--;
}
reverse(ALL(ps));
rep(i,0,k)cout<<ps[i]<<endl;
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... |