#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
struct node {
  int time;
  int cost;
  int fin;
} f[300010];
bool use[600010];
int ans[600010];
bool cmp(node x, node y) {
  if (x.cost == y.cost) return x.time < y.time;
  return x.cost > y.cost;
}
int main() {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    int mi = k + 1;
    memset(use, 0, sizeof(use));
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &f[i].cost);
      f[i].time = i;
    }
    sort(f + 1, f + n + 1, cmp);
    for (int i = 1; i <= n; i++) {
      int now;
      for (int j = max(mi, f[i].time); j <= n + k; j++) {
        if (use[j] == 0) {
          now = j;
          use[j] = 1;
          break;
        }
      }
      f[i].fin = now;
      if (mi == now) {
        mi++;
        while (use[mi] == 1) {
          mi++;
        }
      }
      ans[f[i].time] = now;
    }
    long long int sum = 0;
    for (int i = 1; i <= n; i++) {
      sum += 1LL * f[i].cost * (f[i].fin - f[i].time);
    }
    cout << sum << endl;
    for (int i = 1; i <= n; i++) {
      printf("%d", ans[i]);
      if (i == n)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}
