#include <bits/stdc++.h>
using namespace std;
long long t[300006];
long long ans[300006];
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> t[i];
  priority_queue<pair<long long, long long> > Q;
  for (long long i = 0; i < k; i++) Q.push(pair<long long, long long>(t[i], i));
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (i + k < n) Q.push(pair<long long, long long>(t[i + k], i + k));
    ans[Q.top().second] = i;
    Q.pop();
  }
  for (long long i = 0; i < n; i++) sum += t[i] * (ans[i] - i + k);
  cout << sum << endl;
  for (long long i = 0; i < n; i++) {
    if (i) cout << ' ';
    cout << ans[i] + k + 1;
  }
  cout << endl;
}
