#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
struct node {
  int pre, c;
  bool operator<(const node &a) const { return c < a.c; }
} nodes[maxn];
int n, k;
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &nodes[i].c);
      nodes[i].pre = i;
    }
    priority_queue<node> q;
    for (int i = 1; i <= k; i++) q.push(nodes[i]);
    long long sum = 0;
    for (int i = k + 1; i <= k + n; i++) {
      if (i <= n) q.push(nodes[i]);
      node now = q.top();
      q.pop();
      sum += (long long)(i - now.pre) * now.c;
      nodes[now.pre].pre = i;
    }
    printf("%lld\n", sum);
    for (int i = 1; i < n; i++) printf("%d ", nodes[i].pre);
    printf("%d\n", nodes[n].pre);
  }
  return 0;
}
