#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, j;
  scanf("%lld %lld", &n, &k);
  priority_queue<pair<long long, long long> > pq;
  long long arr[n + 1];
  for (i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  for (i = 1; i <= min(n, k + 1); i++) {
    pq.push({arr[i], i});
  }
  long long ans[n + 1], cnt = 0;
  k++;
  while (pq.size()) {
    long long p = pq.top().second, val = pq.top().first;
    pq.pop();
    ans[p] = k;
    cnt += (k - p) * val;
    k++;
    if (k <= n) {
      pq.push({arr[k], k});
    }
  }
  printf("%lld\n", cnt);
  for (i = 1; i <= n; i++) {
    printf("%lld ", ans[i]);
  }
  printf("\n");
  return 0;
}
