#include <bits/stdc++.h>
using namespace std;
struct node {
  int data;
  int idx;
  bool operator<(const node &n) const { return n.data > data; }
};
const int MAX = 310000;
struct node A[MAX];
priority_queue<struct node> pq;
int main(void) {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    for (int i = 1; i <= n; i++) {
      A[i].idx = i;
      scanf("%d", &A[i].data);
      if (i <= k + 1) pq.push(A[i]);
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      struct node tmp = pq.top();
      pq.pop();
      ans += 1LL * (i + k - tmp.idx) * tmp.data;
      A[tmp.idx].idx = i + k;
      if (k + 1 + i <= n) pq.push(A[k + 1 + i]);
    }
    printf("%lld\n", ans);
    for (int i = 1; i <= n; i++) printf("%d%c", A[i].idx, i == n ? '\n' : ' ');
  }
  return 0;
}
