#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, id;
  bool operator<(const node &r) const {
    if (x == r.x) return id < r.id;
    return x > r.x;
  }
} e[300005];
int pre[2 * 300005], ans[300005];
int Find(int x) { return x == pre[x] ? x : pre[x] = Find(pre[x]); }
int main() {
  int n, m, x;
  long long res = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &e[i].x);
    e[i].id = i;
  }
  sort(e + 1, e + n + 1);
  for (int i = 0; i < 2 * 300005; i++) pre[i] = i;
  for (int i = 1; i <= n; i++) {
    if (e[i].id > m)
      x = e[i].id;
    else
      x = m + 1;
    x = Find(pre[x]);
    ans[e[i].id] = x;
    res += 1LL * (x - e[i].id) * e[i].x;
    pre[x] = x + 1;
  }
  printf("%lld\n", res);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}
