제출 #398095

#제출 시각아이디문제언어결과실행 시간메모리
398095tengiz05수열 (APIO14_sequence)C++17
33 / 100
2072 ms3832 KiB
#include <bits/stdc++.h>
using namespace std;
inline long long msb(long long val){return 63-__builtin_clzll(val);}
inline int msb(int val){return 31-__builtin_clz(val);}
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 1e5+5;
int a[N], n, m, k;
vector<int> old_dp, new_dp;
int par[200][N];
int cost(int l, int r){
	return (a[r] - a[l-1]) * (a[n]-a[r]);
}
void solve(int test_case){
	int i, j;
	cin >> n >> k;
	old_dp.assign(n+1,0);
	new_dp.assign(n+1,0);
	for(i=1;i<=n;i++)cin >> a[i], a[i] += a[i-1];
	for(i=1;i<=n;i++){
		new_dp[i] = cost(1,i);
		par[1][i] = 0;
	}
	for(j=2;j<=k;j++){
		swap(old_dp, new_dp);
		for(i=1;i<=n;i++){
			new_dp[i] = 0;
			for(int l=1;l<i;l++){
				if(chmax(new_dp[i], old_dp[l] + cost(l+1, i)))par[j][i] = l;
			}
		}
	}
	int ans = -1, idx = -1;
	for(i=1;i<=n;i++)if(chmax(ans, new_dp[i]))idx = i;
	cout << ans << '\n';
	vector<int> res;
	for(j=k;j>=1;j--){
		res.pb(idx);
		idx = par[j][idx];
	}reverse(all(res));
	for(auto x : res)cout << x << ' ';
	cout << '\n';
	return;
}

signed main(){
	FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...