#include <bits/stdc++.h>
using namespace std;
using namespace std;
struct node {
  long long p, c;
  node(long long a = 0, long long b = 0) {
    p = a;
    c = b;
  }
};
struct cmp {
  bool operator()(node x, node y) {
    if (x.c != y.c) return x.c > y.c;
    return x.p < y.p;
  }
};
set<node, cmp> s;
int a[300000 + 50];
int main() {
  long long k;
  int n;
  scanf("%d%I64d", &n, &k);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long c;
    scanf("%I64d", &c);
    s.insert(node(i, c));
    if (i >= k + 1) {
      a[s.begin()->p] = i;
      ans += s.begin()->c * (i - s.begin()->p);
      s.erase(s.begin());
    }
  }
  for (int i = 1; i <= k; i++) {
    a[s.begin()->p] = i + n;
    ans += s.begin()->c * (i + n - s.begin()->p);
    s.erase(s.begin());
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
}
