#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const long long maxN = 1000000000;
int n, k, vt[maxn], cs[maxn], tree[4 * maxn];
long long a[maxn];
void buildtree(int pos, int l, int r) {
  if (l == r) {
    tree[pos] = l;
    cs[l] = pos;
    return;
  }
  int m = (l + r) / 2;
  buildtree(2 * pos + 1, l, m);
  buildtree(2 * pos + 2, m + 1, r);
  if (a[tree[2 * pos + 1]] >= a[tree[2 * pos + 2]])
    tree[pos] = tree[2 * pos + 1];
  else
    tree[pos] = tree[2 * pos + 2];
}
int get(int pos, int a1, int b, int l, int r) {
  if (l > r || b < l || a1 > r) return 0;
  if (l <= a1 && b <= r) return tree[pos];
  int m = (a1 + b) / 2, p = get(2 * pos + 1, a1, m, l, r),
      q = get(2 * pos + 2, m + 1, b, l, r);
  if (a[p] >= a[q])
    return p;
  else
    return q;
}
void update(int x) {
  int pos = cs[x];
  a[x] = -maxN;
  while (pos != 0) {
    pos = (pos - 1) / 2;
    if (a[tree[2 * pos + 1]] >= a[tree[2 * pos + 2]])
      tree[pos] = tree[2 * pos + 1];
    else
      tree[pos] = tree[2 * pos + 2];
  }
}
int main() {
  int i, x;
  long long res = 0;
  cin >> n >> k;
  a[0] = -maxN;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    res -= (a[i] * i);
  }
  buildtree(0, 1, n);
  for (i = k + 1; i <= n + k; i++) {
    x = get(0, 1, n, 1, min(i, n));
    vt[x] = i;
    res += (a[x] * i);
    update(x);
  }
  cout << res << "\n";
  for (i = 1; i <= n; i++) cout << vt[i] << " ";
  return 0;
}
