#include <bits/stdc++.h>
using namespace std;
struct CostTime {
  long long cost;
  long long time;
  CostTime(long long c, long long t) : cost(c), time(t) {}
};
bool operator<(const CostTime& a, const CostTime& b) { return a.cost < b.cost; }
int main(void) {
  long long n, k;
  cin >> n >> k;
  long long cost = 0;
  priority_queue<CostTime, vector<CostTime> > pq;
  long long c;
  long long leave[n];
  for (long long t = 1; t <= k; t++) {
    cin >> c;
    CostTime costtime(c, t);
    pq.push(costtime);
  }
  for (long long t = k + 1; t <= k + n; t++) {
    if (t <= n) {
      cin >> c;
      CostTime costtime(c, t);
      pq.push(costtime);
    }
    CostTime latest = pq.top();
    pq.pop();
    leave[latest.time - 1] = t;
    cost += (t - latest.time) * latest.cost;
  }
  cout << cost << endl;
  for (long long t = 0; t < n; t++) {
    cout << leave[t] << " ";
  }
  cout << endl;
  return 0;
}
