#include <bits/stdc++.h>
using namespace std;
long long pw(long long x, long long y) {
  if (y == 0) return 1;
  long long p = pw(x, y / 2);
  if (y % 2) return x * p * p;
  return p * p;
}
priority_queue<pair<long long, long long> > pq;
long long arr[1000000];
int main() {
  long long n, k;
  cin >> n >> k;
  long long ss = 0;
  for (long long i = 1; i < n + 1 + k; ++i) {
    if (i <= n) {
      long long x;
      cin >> x, pq.push(make_pair(x, i));
    }
    if (i > k) {
      pair<long long, long long> cur = pq.top();
      pq.pop();
      ss += (i - cur.second) * cur.first;
      arr[cur.second] = i;
    }
  }
  cout << ss << endl;
  for (long long i = 1; i < n + 1; ++i) cout << arr[i] << " ";
}
