#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll ara[300005], ans_ara[300005];
set<ll> st;
vector<pair<ll, ll> > vv;
int main() {
  ll n, k, i, j, ans = 0;
  scanf("%I64d %I64d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &ara[i]);
    ans -= (ara[i] * i);
    st.insert(i + k);
    vv.push_back({ara[i], i});
  }
  sort(vv.rbegin(), vv.rend());
  for (pair<ll, ll> u : vv) {
    ll num = *st.lower_bound(u.second);
    ans += (num * u.first);
    st.erase(st.lower_bound(u.second));
    ans_ara[u.second] = num;
  }
  printf("%I64d\n", ans);
  for (i = 1; i <= n; i++) {
    printf("%I64d ", ans_ara[i]);
  }
  printf("\n");
  return 0;
}
