#include <bits/stdc++.h>
using namespace std;
struct plane {
  int dep, cost, expec;
};
plane flight[300005];
bool comp(plane x, plane y) {
  if (x.cost == y.cost) return x.dep < y.dep;
  return x.cost > y.cost;
}
int main() {
  int n, k, a;
  scanf("%d%d", &n, &k);
  int order[n], clock[n];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    flight[i].cost = a;
    flight[i].dep = i + 1;
    order[i] = -1;
    clock[i] = -1;
  }
  sort(flight, flight + n, comp);
  long long time = k + 1, it = 0;
  while (it < n) {
    if (flight[it].dep > time) {
      flight[it].expec = flight[it].dep;
      order[flight[it].dep - 1] = flight[it].dep;
      clock[flight[it].expec - (k + 1)] = 0;
    } else {
      while (clock[time - (k + 1)] != -1) {
        time++;
      }
      flight[it].expec = time;
      order[flight[it].dep - 1] = time;
      ans += (flight[it].cost) * (time - flight[it].dep);
      time++;
    }
    it++;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << order[i] << " ";
  return 0;
}
