#include <bits/stdc++.h>
struct Airport {
  int num;
  long long cost;
} air[301108];
bool bj(Airport a1, Airport a2);
int book[601108] = {0};
long t[301108];
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    air[i].num = i + 1;
    scanf("%lld", &air[i].cost);
  }
  long long cost = 0;
  std::sort(air, air + n, bj);
  for (i = 0, j = 1; i < n; i++) {
    long x = air[i].num;
    if (x >= k + 1 && !book[x]) {
      t[x] = x;
      book[x] = 1;
    } else {
      while ((k + j) < x || book[k + j]) j++;
      t[x] = k + j;
      book[k + j] = 1;
      j++;
    }
    cost += (t[x] - x) * air[i].cost;
  }
  printf("%lld\n", cost);
  for (i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", t[i]);
  }
  printf("\n");
  return 0;
}
bool bj(Airport a1, Airport a2) {
  if (a1.cost != a2.cost) return a1.cost > a2.cost;
  return a1.num > a2.num;
}
