#include <bits/stdc++.h>
using namespace std;
struct node {
  long long cos, rlev;
  bool operator<(const node &a) const { return cos < a.cos; }
} f[300005];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", &f[i].cos);
      f[i].rlev = i;
    }
    priority_queue<node> p;
    long long ans = 0;
    for (int i = 1; i <= k; i++) p.push(f[i]);
    for (int i = k + 1; i <= k + n; i++) {
      if (i <= n) p.push(f[i]);
      node now = p.top();
      p.pop();
      if (i >= now.rlev) {
        ans += (i - now.rlev) * now.cos;
        f[now.rlev].rlev = i;
      }
    }
    printf("%I64d\n", ans);
    for (int i = 1; i < n; i++) {
      printf("%I64d ", f[i].rlev);
    }
    printf("%I64d\n", f[n].rlev);
  }
  return 0;
}
