#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, j;
  cin >> n >> k;
  vector<pair<long long, long long> > a(n);
  priority_queue<pair<long long, long long> > b;
  long long ans[n];
  for (i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    if (i < k) {
      b.push(a[i]);
    }
  }
  long long z = k + 1;
  long long sum = 0;
  for (i = k; i < n; i++, z++) {
    b.push(a[i]);
    ans[b.top().second] = z;
    sum += (b.top().first * (z - b.top().second - 1));
    b.pop();
  }
  while (!b.empty()) {
    ans[b.top().second] = z;
    sum += (b.top().first * (z - b.top().second - 1));
    b.pop();
    z++;
  }
  cout << sum << endl;
  for (i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
