#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, u;
  cin >> n >> k;
  map<pair<int, int>, int> cost;
  map<int, int> pos;
  for (int i = 1; i <= n; i++) {
    cin >> u;
    pos[k + i];
    cost[make_pair(u, i)];
  }
  int fin[n + 1];
  long long int ans = 0;
  for (map<pair<int, int>, int>::reverse_iterator rit = cost.rbegin();
       rit != cost.rend(); rit++) {
    u = (rit->first).second;
    int v = (pos.lower_bound(u))->first;
    ans += 1LL * (v - u) * ((rit->first).first);
    pos.erase(v);
    fin[u] = v;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << fin[i] << " ";
  }
  cout << endl;
}
