Submission #162273

#TimeUsernameProblemLanguageResultExecution timeMemory
162273amoo_safarSplit the sequence (APIO14_sequence)C++14
0 / 100
13 ms2736 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
//const ll N = 1ll << Log;
const int Maxn = 1e5;
const int Base = 101;
typedef pair<pll, ll> node;

ll a[Maxn], mk[Maxn];
ll ps[Maxn], sf[Maxn];

vector<ll> A;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	ll ans = 0;
	
	mk[0] = 1;
	mk[n] = 1;
	
	for(int j = 0; j < k; j++){
		ps[0] = 0;
		for(int i = 1; i <= n; i++) ps[i] = (mk[i] ? 0 : ps[i - 1] + a[i - 1]);
		sf[n] = 0;
		for(int i = n - 1; i >= 0; i--) sf[i] = (mk[i] ? 0 : sf[i + 1] + a[i]);
		ll mx = -1;
		ll ind = 0;
		for(int i = 0; i <= n; i++){
			if(mk[i]) continue;
			if(ps[i] * sf[i] > mx){
				mx = ps[i] * sf[i];
				ind = i;
			}
		}
		
		ans += mx;
		mk[ind] = 1;
		A.pb(ind);
	}
	
	cout << ans << '\n';
	sort(all(A));
	for(auto x : A) cout << x << ' ';
	cout << '\n';
	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...