#include <bits/stdc++.h>
#define pb push_back
using namespace std;
#define F first
#define sz size()
#define S second
#define in insert
#define lb lower_bound
#define all(v) v.begin(), v.end()
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N = 1e6+5;
int n,m,k,tt,ans,sum=0,l, r, x, y, cnt, block = 448, res;
int a[N], b[N], c[N], dp[N], pref[N];
void solve() {
cin >> n >> m;
FOR(i, 1, n, 1)cin >> a[i], pref[i] = pref[i-1] + a[i];
int mx = 0;
set<int>st;
st.in(n);
set<int, greater<int>>st1;
st1.in(0);
vector<int>v;
FOR(ok, 1, m, 1){
int mx = 0;
x=y=0;
int lp = 0;
FOR( i, 1, n, 1 ){
l = *st1.lb(i), r = *st.lb(i);
if(mx < (pref[i] - pref[l]) * (pref[r] - pref[i]))mx = (pref[i] - pref[l]) * (pref[r] - pref[i]), x = l, y = r, lp = i;
}
ans += mx;
st.erase(y), st1.erase(x);
st.in(lp), st1.in(x);
st.in(r), st1.in(lp);
v.pb(lp);
}
cout << ans << '\n';
for(auto i : v)cout<<i<<' ';
}
signed main()
{
nikita
tt = 1;
if(!tt)cin >> tt;
FOR(i, 1, tt, 1){
solve();
}
}
# | 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... |