#include <bits/stdc++.h>
using namespace std;
struct node {
  int c;
  int t;
} pl[300005];
int ans[300005];
set<int> ss;
int cmp(struct node a, struct node b) {
  if (a.c == b.c)
    return a.t < b.t;
  else
    return a.c > b.c;
}
int main() {
  int n, k;
  long long int sum = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &pl[i].c);
    pl[i].t = i;
    ss.insert(k + i);
  }
  sort(pl + 1, pl + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    int tt = *ss.upper_bound(pl[i].t - 1);
    sum += (long long)(tt - pl[i].t) * pl[i].c;
    ans[pl[i].t] = tt;
    ss.erase(tt);
  }
  printf("%lld\n", sum);
  for (int i = 1; i <= n; i++) {
    printf("%d", ans[i]);
    if (i == n)
      putchar('\n');
    else
      printf(" ");
  }
  return 0;
}
