#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int n, k;
struct flight {
  int c, num;
  bool operator<(const flight &x) const { return c < x.c; }
} f[MAXN];
int t[MAXN];
priority_queue<flight> q;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i].c);
    f[i].num = i;
  }
  long long ans = 0;
  for (int i = 1; i <= k + n; i++) {
    if (i <= n) q.push(f[i]);
    if (i >= k + 1) {
      flight x = q.top();
      q.pop();
      ans += 1ll * x.c * (i - x.num);
      t[x.num] = i;
    }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) printf("%d ", t[i]);
  return 0;
}
