#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
priority_queue<pair<long long, long long> > pq;
long long ara[333333];
long long v[333333];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
    if (i <= k) {
      pq.push(make_pair(ara[i], i));
    }
  }
  long long ans = 0;
  for (long long i = k + 1; i <= n + k; i++) {
    if (i <= n) {
      pq.push(make_pair(ara[i], i));
    }
    pair<long long, long long> t = pq.top();
    pq.pop();
    ans += (i - t.second) * t.first;
    v[t.second] = i;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << v[i] << ' ';
  }
  cout << endl;
  return 0;
}
