제출 #855370

#제출 시각아이디문제언어결과실행 시간메모리
855370vjudge1Split the sequence (APIO14_sequence)C++17
0 / 100
2090 ms69604 KiB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define int long long

const int maxn = 2e5+7;
const int inf = 1e18;
const int mod = 1e9+7;
using namespace std;

int n, k;
int a[maxn];
int pref[maxn];
int res;
bool was[maxn];
vector<int> total;

void rec(int i, int cnt, int ans, set<int> st){	
	if(cnt == k){
		if(res < ans){
			res = ans;
			total.clear();
			for(auto it : st){
				total.pb(it);
			}
		}
		return;
	}
	if(i == n + 1) return;
	rec(i + 1, cnt, ans, st);
	if(!st.count(i)){
		int left = 0, right = n + 1;
		auto l = st.upper_bound(i);
		
		if(st.size() != 0){
			if(l != st.end()) right = *l;
			if(l != st.begin()) left = *(--l);
		}
		
		int add = (pref[i] - pref[left]) * (pref[right - 1] - pref[i + 1 - 1]);
		st.insert(i);
		rec(1, cnt + 1, ans + add, st);
		st.erase(i);
	}
}

set<int> ex;

void solve(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	rec(1, 0, 0, ex);
	cout << res << '\n';
	for(auto x : total) cout << x << ' ';
}

signed main(){
	speed
	int test = 1;
//	cin >> test;
	while(test--){
		solve();
	}
}


#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...