#include <bits/stdc++.h>
using namespace std;
struct Myp {
  long long fi;
  long long la;
};
inline bool cmp(Myp p1, Myp p2) { return (p1.fi > p2.fi); };
Myp c[300010];
bool used[2 * 300010];
long long ans, cur;
long long ans2[300010];
int main() {
  long long n, k;
  scanf("%I64d%I64d", &n, &k);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d", &c[i].fi);
    c[i].la = i + 1;
  };
  sort(c, c + n, cmp);
  cur = k + 1;
  for (long long i = 0; i < n; i++) {
    while (used[cur]) cur++;
    if (cur < c[i].la) {
      used[c[i].la] = true;
      ans2[c[i].la] = c[i].la;
    } else {
      ans += (cur - c[i].la) * c[i].fi;
      ans2[c[i].la] = cur;
      used[cur] = true;
      cur++;
    };
  };
  printf("%I64d\n", ans);
  for (long long i = 1; i <= n; i++) printf("%d ", ans2[i]);
  return 0;
};
