#include <bits/stdc++.h>
long long ans, c[300010];
int id[300010], n, k, f[300010 * 4], ans1[300010];
using namespace std;
bool cmp(int p1, int p2) { return c[p1] > c[p2]; }
void build(int ro, int l, int r) {
  if (l == r) {
    f[ro] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(ro << 1, l, mid);
  build(ro << 1 | 1, mid + 1, r);
  f[ro] = min(f[ro << 1], f[ro << 1 | 1]);
}
int fnd(int ro, int l, int r, int l1, int r1) {
  if (l == l1 && r == r1) return f[ro];
  int mid = (l + r) >> 1;
  if (mid >= r1) return fnd(ro << 1, l, mid, l1, r1);
  if (mid < l1)
    return fnd(ro << 1 | 1, mid + 1, r, l1, r1);
  else
    return min(fnd(ro << 1, l, mid, l1, mid),
               fnd(ro << 1 | 1, mid + 1, r, mid + 1, r1));
}
void del(int ro, int l, int r, int tar) {
  if (l == r) {
    f[ro] = 0x7f7f7f7f;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= tar)
    del(ro << 1, l, mid, tar);
  else
    del(ro << 1 | 1, mid + 1, r, tar);
  f[ro] = min(f[ro << 1], f[ro << 1 | 1]);
}
int main() {
  ans = 0LL;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%I64d", &c[i]);
  build(1, k + 1, n + k);
  for (int i = 1; i <= n; i++) id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    int tmp = fnd(1, k + 1, n + k, max(id[i], k + 1), n + k);
    ans1[id[i]] = tmp;
    del(1, k + 1, n + k, tmp);
    ans += c[id[i]] * (tmp - id[i]);
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", ans1[i]);
  printf("\n");
}
