#include <bits/stdc++.h>
using namespace std;
struct node {
  int id, c;
};
node a[300010];
bool cmp(node a, node b) {
  if (a.c == b.c) return a.id < b.id;
  return a.c > b.c;
}
int ans[300010];
set<int> s;
int main(void) {
  int n, k, i, j;
  while (scanf("%d%d", &n, &k) == 2) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i].c);
      a[i].id = i;
      s.insert(k + i);
    }
    sort(a + 1, a + 1 + n, cmp);
    long long sum = 0;
    for (i = 1; i <= n; i++) {
      int p = *s.upper_bound(a[i].id - 1);
      ans[a[i].id] = p;
      sum += (long long)(p - a[i].id) * a[i].c;
      s.erase(p);
    }
    printf("%I64d\n", sum);
    for (i = 1; i <= n; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
