#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long ini;
  long long cost;
  bool operator<(const edge& p) const { return cost < p.cost; }
  void setv(long long a, long long b) {
    ini = a;
    cost = b;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  priority_queue<edge> pq;
  int n, k;
  cin >> n >> k;
  vector<edge> mv;
  edge temp;
  for (long long i = 1; i <= n; i++) {
    long long c;
    cin >> c;
    temp.setv(i, c);
    mv.push_back(temp);
  }
  int j = 0;
  long long tot = 0;
  long long ara[n + 5];
  for (int i = k + 1; i <= k + n; i++) {
    if (j == mv.size() && pq.empty()) break;
    while (mv[j].ini <= i && j < mv.size()) {
      temp = mv[j];
      pq.push(temp);
      j++;
    }
    if (!pq.empty()) {
      temp = pq.top();
      pq.pop();
      ara[temp.ini] = i;
      tot += (i - temp.ini) * temp.cost;
    }
  }
  cout << tot << "\n";
  for (int i = 1; i <= n; i++) cout << ara[i] << " ";
}
