#include <bits/stdc++.h>
using namespace std;
long long n, k, x, sum = 0, a[300003];
priority_queue<pair<long long, long long> > q;
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    ;
    q.push({x, i});
    if (i > k) {
      sum += (i - q.top().second) * q.top().first;
      a[q.top().second] = i;
      q.pop();
    }
  }
  for (int i = n + 1; i <= n + k; i++) {
    sum += (i - q.top().second) * q.top().first;
    a[q.top().second] = i;
    q.pop();
  }
  cout << sum << endl;
  for (int i = 1; i < n; i++) cout << a[i] << " ";
  cout << a[n] << "\n";
}
