/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define M5 100009
#define M6 1000009
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
ll fac[M6],ar[M6];
bool prime01[M6],mark[10000];
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1]);
}
void sieve(ll m){
    memset(prime01,1,sizeof(prime01));
    prime01[1]=0; prime01[0]=0;
    for(ll p=2;p*p<m;p++){
        if(prime01[p]){
            for(ll i=p*2;i<m;i+=p) prime01[i]=0;
        }
    }
    //for(ll i=2;i<m;i++) if(prime01[i]) prime.pb(i);
}
int main(){
    buf;
    //sieve(M6);
    //fact();
    ll i,j,k,n,m,test,ans,a,b,t; string s; 
    test=1;
    while(test--){
        cin>>n>>k;
        std::vector<P> v;
        for(i=1;i<=n;i++){
            cin>>ar[i];
            v.pb({ar[i],i});
        }
        sort(v.begin(),v.end());
        map<ll,ll> vis,out;
        ans=0;
        set<ll> ss;
        for(i=k+1;i<=k+n;i++) ss.insert(i);
        for(i=n-1;i>=0;i--){
            j=max(v[i].second,k+1);
            auto it=ss.lower_bound(j);
            out[v[i].second]=*it;
            ss.erase(it);
            ans+=(*it-v[i].second)*v[i].first;
        }
        cout<<ans<<"\n";
        for(i=1;i<=n;i++) cout<<out[i]<<" ";
    }
    return 0;
}