#include <bits/stdc++.h>
using namespace std;
const int MaxN = 300 * 1000;
long long c[MaxN + 5];
long long dep[MaxN + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> c[i];
  set<pair<long long, long long>> s;
  for (int i = min(n, k); i >= 1; i--) s.insert({c[i], i});
  long long fee = 0;
  for (int tm = 1; tm <= n; tm++) {
    if (k + tm <= n) {
      s.insert({c[k + tm], k + tm});
    }
    auto p = *s.rbegin();
    s.erase(p);
    fee += (k + tm - p.second) * p.first;
    dep[p.second] = k + tm;
  }
  cout << fee << endl;
  for (int i = 1; i <= n; i++) cout << dep[i] << " ";
  cout << endl;
  return 0;
}
