#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
/**zagaro & lauren <3**/
#define mod 1000000007 //1e9 + 7
#define pi acos(-1)
#define wl while
#define str string
#define ENDL "\n"
#define sal ' '
#define tp_set ll
#define prc(n) cout.precision(n);cout<<fixed;
#define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef bool bl;
typedef char car;
using namespace std;
using namespace __gnu_pbds;
vector<ll> prf;
tuple<ll,ll,ll,ll> fun(ll x, ll y){
    ll t, l, r, m, v, aux;
    tuple<ll,ll,ll,ll> a, b;
    t = prf[y]-prf[x-1];
    l=x;r=y;
    wl(l<r-1){
        m = (l+r)/2;
        if(prf[m]-prf[x-1] <= t/2)l=m;
        else r=m;
    }
    aux = prf[l]-prf[x-1];
    a = {(aux)*(t-aux), x, y, l};
    aux = prf[r]-prf[x-1];
    r != y?b = {(aux)*(t-aux), x, y, r}:b={-1, x, y, l};
    return max(a, b);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, k, R=0, v, x, y, p, l, r, m, t;
    cin>>n>>k;
    vector<ll> vec(n+1, 0);
    prf.assign(n+1, 0);
    vector<ll> res;
    for(int i=1;i<=n;i++){
        cin>>vec[i];
        prf[i] = prf[i-1] + vec[i];
    }
    priority_queue<tuple<ll,ll,ll,ll> > pq;
    pq.push(fun(1, n));
    wl(k--){
        tie(v, x, y, p) = pq.top();
        pq.pop();
        R+=v;
        res.push_back(p);
        if(x != p)pq.push(fun(x, p));
        if(p+1 != y)pq.push(fun(p+1, y));
    }
    cout<<R<<ENDL;
    for(auto i: res)cout<<i<<sal;
    cout<<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... |