#include <bits/stdc++.h>
using namespace std;
struct node {
  int cost;
  int p;
  friend bool operator<(node a, node b) { return a.cost < b.cost; }
};
int arr[300005];
priority_queue<node> q;
int main() {
  int n, k;
  long long sum = 0;
  node x;
  scanf("%d%d", &n, &k);
  k++;
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x.cost);
    x.p = i;
    q.push(x);
    if (i == k) {
      node temp = q.top();
      q.pop();
      arr[temp.p - 1] = k;
      sum += (long long)(k - temp.p) * temp.cost;
      k++;
    }
  }
  while (!q.empty()) {
    node temp = q.top();
    q.pop();
    arr[temp.p - 1] = k;
    sum += (long long)(k - temp.p) * temp.cost;
    k++;
  }
  printf("%lld\n", sum);
  for (int i = 0; i < n; i++) {
    if (i)
      printf(" %d", arr[i]);
    else
      printf("%d", arr[i]);
  }
}
