#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tot = 0LL;
  long long n, k, c = 1LL;
  cin >> n >> k;
  vector<pair<long long, long long>> v(n);
  vector<long long> f(k + n + 5), pos(n + 1);
  for (int i = 0; i < n; i++) v[i].second = i + 1, cin >> v[i].first;
  sort(v.begin(), v.end(), greater<pair<long long, long long>>());
  for (int i = 0; i < n; i++) {
    if (v[i].second > k && !f[v[i].second]) {
      pos[v[i].second] = v[i].second;
      f[v[i].second] = 1;
      tot += v[i].first * (pos[v[i].second] - v[i].second);
    } else {
      while (f[k + c]) c++;
      pos[v[i].second] = k + c;
      f[k + c] = 1;
      c++;
      tot += v[i].first * (pos[v[i].second] - v[i].second);
    }
  }
  cout << tot << endl;
  for (int i = 1; i <= n; i++) {
    cout << pos[i] << " ";
  }
}
