#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 61;
const long long mod = 1000000007;
const int maxn = 3e5 + 10;
long long c[maxn], a[maxn];
priority_queue<pair<long long, int> > que;
int main() {
  std::ios::sync_with_stdio(false);
  int n, k;
  long long sum = 0, ans = 0;
  ;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
    if (i <= k) {
      que.push(make_pair(c[i], i));
      sum += c[i];
      ans += sum;
    }
  }
  pair<long long, int> tmp;
  for (int i = k + 1; i <= k + n; i++) {
    if (i <= n) {
      que.push(make_pair(c[i], i));
      sum += c[i];
    }
    tmp = que.top();
    que.pop();
    sum -= tmp.first;
    ans += sum;
    a[tmp.second] = i;
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%lld%c", a[i], i == n ? '\n' : ' ');
  }
  return 0;
}
