#include <bits/stdc++.h>
using namespace std;
struct Nod {
  long long x, y;
  friend bool operator<(Nod l, Nod r) { return l.x < r.x; }
};
long long i, j, k, l, n, m, x, ans, Ans[300005];
Nod z, tmp;
priority_queue<Nod> Q;
int main() {
  scanf("%I64d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%I64d", &x);
    z.x = x;
    z.y = i;
    Q.push(z);
  }
  for (i = m + 1; i <= n; i++) {
    scanf("%I64d", &x);
    z.x = x;
    z.y = i;
    Q.push(z);
    tmp = Q.top();
    ans += tmp.x * (i - tmp.y);
    Ans[tmp.y] = i;
    Q.pop();
  }
  for (; !Q.empty(); i++) {
    tmp = Q.top();
    Q.pop();
    ans += tmp.x * (i - tmp.y);
    Ans[tmp.y] = i;
  }
  printf("%I64d\n", ans);
  for (i = 1; i <= n; i++) printf("%I64d ", Ans[i]);
}
