#include <bits/stdc++.h>
using namespace std;
struct mystruct {
  int v;
  mystruct *next;
};
int structcmp(const void *v1, const void *v2) {
  return ((mystruct *)v1)->v - ((mystruct *)v2)->v;
}
int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }
long long minn(long long v1, long long v2) { return v1 < v2 ? v1 : v2; }
long long maxx(long long v1, long long v2) { return v1 > v2 ? v1 : v2; }
int n, k;
int val[600010] = {0};
int heapsize = 0;
int hhheap[600010] = {0};
void inserth(int v) {
  hhheap[++heapsize] = v;
  int no = heapsize;
  while (no != 1) {
    int fa = no / 2;
    int noindex = hhheap[no];
    int faindex = hhheap[fa];
    if (val[noindex] > val[faindex]) {
      int tmp = hhheap[no];
      hhheap[no] = hhheap[fa];
      hhheap[fa] = tmp;
      no = fa;
    } else {
      break;
    }
  }
}
int outh() {
  if (heapsize == 0) return -1;
  int ret = hhheap[1];
  hhheap[1] = hhheap[heapsize];
  int no = 1;
  while (no <= heapsize) {
    int l = no * 2, r = l + 1;
    if (l > heapsize) break;
    if (r > heapsize) {
      if (val[hhheap[no]] < val[hhheap[l]]) {
        int tmp = hhheap[no];
        hhheap[no] = hhheap[l];
        hhheap[l] = tmp;
      }
      break;
    }
    if (val[hhheap[l]] > val[hhheap[r]]) {
      if (val[hhheap[no]] < val[hhheap[l]]) {
        int tmp = hhheap[no];
        hhheap[no] = hhheap[l];
        hhheap[l] = tmp;
        no = l;
      } else {
        break;
      }
    } else {
      if (val[hhheap[no]] < val[hhheap[r]]) {
        int tmp = hhheap[no];
        hhheap[no] = hhheap[r];
        hhheap[r] = tmp;
        no = r;
      } else {
        break;
      }
    }
  }
  heapsize--;
  return ret;
}
int resnum = 0;
int res[300010] = {0};
int ans[300010] = {0};
long long calcres() {}
int main() {
  cin >> n >> k;
  int i;
  for (i = 0; i < n; i++) scanf("%d", &val[i]);
  for (i = 0; i < k; i++) {
    inserth(i);
  }
  int offset = 0;
  for (; i < n; i++) {
    inserth(i);
    res[offset++] = outh();
  }
  int ret;
  while ((ret = outh()) != -1) {
    res[offset++] = ret;
  }
  for (i = 0; i < offset; i++) {
    ans[res[i]] = i + k + 1;
  }
  long long anscnt = 0;
  for (i = 0; i < offset; i++) {
    anscnt += ((long long)(val[i])) * (ans[i] - i - 1);
  }
  cout << anscnt << endl;
  for (i = 0; i < offset; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
