#include <bits/stdc++.h>
using namespace std;
int n, K, w[301000], res[301000];
long long S;
priority_queue<pair<int, int> > PQ;
int main() {
  int pv = 1;
  cin >> n >> K;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = K + 1; i <= K + n; i++) {
    while (pv <= n && pv <= i) {
      PQ.push(pair<int, int>(w[pv], pv));
      pv++;
    }
    pair<int, int> tp = PQ.top();
    PQ.pop();
    S += 1ll * tp.first * (i - tp.second);
    res[tp.second] = i;
  }
  cout << S << endl;
  for (int i = 1; i <= n; i++) cout << res[i] << ' ';
  cout << endl;
  return 0;
}
