#include <bits/stdc++.h>
using namespace std;
int a[300003], c[300003];
vector<pair<int, int> > v;
map<int, int> m;
int main() {
  int n, k, i, p;
  scanf("%d", &n);
  scanf("%d", &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    v.push_back(make_pair(c[i], i + 1));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  p = k + 1;
  for (i = 0; i < n; i++) {
    if (v[i].second <= p) {
      while (m.find(p) != m.end()) {
        p++;
      }
      a[v[i].second - 1] = p;
      m[p] = i;
      p++;
    } else {
      int t = v[i].second;
      while (m.find(t) != m.end()) {
        t++;
      }
      a[v[i].second - 1] = t;
      m[t] = i;
    }
  }
  long long ans = 0;
  for (i = 0; i < n; i++) {
    ans += 1ll * (a[i] - (i + 1)) * c[i];
  }
  cout << ans << endl;
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
