#include <bits/stdc++.h>
using namespace std;
long long c[300020 << 1];
priority_queue<pair<long long, long long> > q;
int t[300020 << 1];
int main(void) {
  int n, k;
  long long i;
  pair<long long, long long> x;
  long long o;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%I64d", &c[i]);
  for (i = 1; i <= k; i++) q.push(make_pair(c[i], i));
  for (i = k + 1, o = 0; i <= k + n; i++) {
    q.push(make_pair(c[i], i));
    x = q.top();
    q.pop();
    o += ((t[x.second] = i) - x.second) * x.first;
  }
  printf("%I64d\n", o);
  for (i = 1; i <= n; i++) printf("%d ", t[i]);
  return 0;
}
