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