#include <bits/stdc++.h>
using namespace std;
int ai[300005], nxt[600005];
int foo(int i) {
  if (nxt[i] == i) {
    nxt[i] = nxt[i + 1];
    return i;
  }
  return nxt[i] = foo(nxt[i]);
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  priority_queue<pair<int, int>> pq;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    pq.emplace(x, i);
  }
  for (int i = k + 1; i <= k + n; i++) nxt[i] = i;
  long long ans = 0;
  while (!pq.empty()) {
    int x, i;
    tie(x, i) = pq.top();
    pq.pop();
    int j = foo(max(k + 1, i));
    ai[i] = j;
    ans += 1LL * x * (j - i);
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", ai[i]);
}
