#include <bits/stdc++.h>
using namespace std;
int c[300000], d[300000];
priority_queue<pair<int, int> > pq;
int main() {
  int i, j, k, n, m;
  long long int cost = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> c[i];
  for (i = 0; i < k; i++) pq.push(make_pair(c[i], i));
  for (i = k; !pq.empty(); i++) {
    if (i < n) pq.push(make_pair(c[i], i));
    pair<int, int> best = pq.top();
    pq.pop();
    cost += (long long int)best.first * (i - best.second);
    d[best.second] = i + 1;
  }
  cout << cost << "\n";
  for (i = 0; i < n; i++) cout << d[i] << " ";
  return 0;
}
