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