#include <bits/stdc++.h>
using namespace std;
long long m = 10000000LL;
long long arr[310000 + 10], brr[310000 + 10];
class prioritize {
 public:
  bool operator()(pair<long long, long long>& p1,
                  pair<long long, long long>& p2) {
    return p1.first < p2.first;
  }
};
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               prioritize>
    q;
int main() {
  long long n, k, i, total = 0, temp, cost;
  pair<long long, long long> u;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
    if (i <= k) q.push(make_pair(arr[i], i));
  }
  for (i = k + 1; !q.empty(); i++) {
    if (i <= n) {
      temp = arr[i];
      u = q.top();
      cost = u.first * (i - u.second);
      if (u.first > arr[i]) {
        brr[u.second] = i;
        total += cost;
        q.pop();
        q.push(make_pair(arr[i], i));
      } else {
        brr[i] = i;
      }
    } else {
      u = q.top();
      cost = u.first * (i - u.second);
      brr[u.second] = i;
      q.pop();
      total += cost;
    }
  }
  cout << total << endl;
  for (i = 1; i <= n; i++) {
    cout << brr[i] << " ";
  }
  cout << endl;
  return 0;
}
