#include <bits/stdc++.h>
using namespace std;
int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  std::ios::sync_with_stdio(false);
  long long int n, k;
  cin >> n >> k;
  set<int> qwer;
  vector<pair<long long int, long long int> > a;
  long long int b[n + 20];
  for (size_t i = 1; i <= n; i++) {
    long long int c;
    cin >> c;
    a.push_back(make_pair(c, i));
    b[i] = 0;
    qwer.insert(k + i);
  }
  sort(a.begin(), a.end());
  long long int cn = 0;
  long long int j;
  long long int j1;
  long long int cer;
  for (int i = a.size() - 1; i >= 0; i--) {
    long long int a3 = *qwer.begin();
    if (a[i].second <= a3) {
      j1 = 0;
      cer = a3;
      qwer.erase(qwer.begin());
    } else {
      cer = a[i].second;
      qwer.erase(qwer.find(cer));
    }
    b[a[i].second] = cer;
    cn = cn + abs(cer - a[i].second) * a[i].first;
  }
  cout << cn << endl;
  for (int i = 1; i <= n - 1; i++) {
    cout << b[i] << " ";
  }
  cout << b[n] << endl;
  return 0;
}
