#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> in(n);
  vector<int> ans(n);
  for (int i = 0; i < n; ++i) cin >> in[i];
  long long ret = 0;
  priority_queue<pair<int, int> > Q;
  while (!Q.empty()) Q.pop();
  k++;
  for (int i = 0; i < k && i < n; ++i) Q.push(make_pair(in[i], i));
  for (int i = k; i < n + k; ++i) {
    auto tmp = Q.top();
    Q.pop();
    ans[tmp.second] = i;
    ret += (long long)abs(i - tmp.second - 1) * tmp.first;
    if (i < n) Q.push(make_pair(in[i], i));
    if (Q.empty()) break;
  }
  cout << ret << endl;
  for (auto a : ans) cout << a << ' ';
  cout << endl;
  return 0;
}
