/*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 300009
#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);
//if(it==ss.end()) {cout<<"."; return 0;}
out[v[i].second]=*it;
ans+=(*it-v[i].second)*v[i].first;
ss.erase(it);
}
cout<<ans<<"\n";
for(i=1;i<=n;i++) cout<<out[i]<<" ";
}
return 0;
}
LypDb2RlZCBieTo6CiAgICAqKkF2aW5hc2ggVGl3YXJ5KioKICAgICoqQkUvMTAyOTgvMjAxNSoqCiAgICAqKlByb2R1Y3Rpb24gRW5naW5lZXIqKgogICAgKipQcm9k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T1wKjI7aTxtO2krPXApIHByaW1lMDFbaV09MDsKICAgICAgICB9CiAgICB9CiAgICAvL2ZvcihsbCBpPTI7aTxtO2krKykgaWYocHJpbWUwMVtpXSkgcHJpbWUucGIoaSk7Cn0KaW50IG1haW4oKXsKICAgIGJ1ZjsKICAgIC8vc2lldmUoTTYpOwogICAgLy9mYWN0KCk7CiAgICBsbCBpLGosayxuLG0sdGVzdCxhbnMsYSxiLHQ7IHN0cmluZyBzOyAKICAgIHRlc3Q9MTsKICAgIHdoaWxlKHRlc3QtLSl7CiAgICAgICAgY2luPj5uPj5rOwogICAgICAgIHN0ZDo6dmVjdG9yPFA+IHY7CiAgICAgICAgZm9yKGk9MTtpPD1uO2krKyl7CiAgICAgICAgICAgIGNpbj4+YXJbaV07CiAgICAgICAgICAgIHYucGIoe2FyW2ldLGl9KTsKICAgICAgICB9CiAgICAgICAgc29ydCh2LmJlZ2luKCksdi5lbmQoKSk7CiAgICAgICAgbWFwPGxsLGxsPiB2aXMsb3V0OwogICAgICAgIGFucz0wOwogICAgICAgIHNldDxsbD4gc3M7CiAgICAgICAgZm9yKGk9aysxO2k8PWsrbjtpKyspIHNzLmluc2VydChpKTsKICAgICAgICBmb3IoaT1uLTE7aT49MDtpLS0pewogICAgICAgICAgICBqPW1heCh2W2ldLnNlY29uZCxrKzEpOwogICAgICAgICAgICBhdXRvIGl0PXNzLmxvd2VyX2JvdW5kKGopOwogICAgICAgICAgICAvL2lmKGl0PT1zcy5lbmQoKSkge2NvdXQ8PCIuIjsgcmV0dXJuIDA7fQogICAgICAgICAgICBvdXRbdltpXS5zZWNvbmRdPSppdDsKICAgICAgICAgICAgYW5zKz0oKml0LXZbaV0uc2Vjb25kKSp2W2ldLmZpcnN0OwogICAgICAgICAgICBzcy5lcmFzZShpdCk7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PGFuczw8IlxuIjsKICAgICAgICBmb3IoaT0xO2k8PW47aSsrKSBjb3V0PDxvdXRbaV08PCIgIjsKICAgIH0KICAgIHJldHVybiAwOwp9