#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n;
  cin >> k;
  vector<long long int> vec;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    vec.push_back(x);
  }
  priority_queue<pair<long long int, long long int> > pq;
  for (long long int i = 0; i < k; i++) {
    pq.push(make_pair(vec[i], i));
  }
  long long int sum = 0;
  vector<long long int> res(n, 0);
  for (long long int i = k; i < n; i++) {
    pq.push(make_pair(vec[i], i));
    pair<long long int, long long int> x = pq.top();
    pq.pop();
    sum += ((long long int)(x.first) * (long long int)(i - x.second));
    res[x.second] = i;
  }
  long long int i = n;
  while (!pq.empty()) {
    pair<long long int, long long int> x = pq.top();
    pq.pop();
    sum += (long long int)((x.first) * (i - x.second));
    res[x.second] = i;
    i++;
  }
  cout << sum << endl;
  for (long long int i = 0; i < n; i++) {
    cout << res[i] + 1 << " ";
  }
}
