#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 9223372036854775806;
const long long int ARR = 3 * 1000 * 100 + 256;
pair<long long int, long long int> p;
priority_queue<pair<long long int, long long int> > q;
long long int a[ARR];
long long int w[ARR];
long long int ans = 0;
int main() {
  long long int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    q.push(make_pair(a[i], i));
  }
  while (q.size() != 0) {
    k++;
    if (k <= n) {
      q.push(make_pair(a[k], k));
    }
    p = q.top();
    q.pop();
    w[p.second] = k;
    ans += p.first * (k - p.second);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << w[i] << " ";
  }
}
