#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  priority_queue<pair<long long int, long long int> > p;
  long long int sum = 0;
  long long int ans[n + 1];
  for (long long int i = 1; i <= n + k; i++) {
    if (i <= n) p.push(pair<long long int, long long int>(a[i], i));
    if (i > k) {
      pair<long long int, long long int> val = p.top();
      p.pop();
      sum += val.first * (i - val.second);
      ans[val.second] = i;
    }
  }
  cout << sum << endl;
  for (long long int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
