#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node {
  int ind, cost;
  bool operator<(const node &r) const { return cost < r.cost; }
};
priority_queue<node> que;
int gp[300005];
int ans[300005];
void solve() {
  int it = 0;
  int tmp = k + 1;
  long long ant = 0;
  node u, v;
  while (!que.empty()) {
    u = que.top();
    que.pop();
    ant += (1ll * u.cost * (tmp - u.ind));
    ans[u.ind] = tmp;
    ++tmp;
    if (tmp <= n) {
      v.cost = gp[tmp];
      v.ind = tmp;
      que.push(v);
    }
  }
  printf("%lld\n%d", ant, ans[1]);
  for (int i = 2; i <= n; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    while (!que.empty()) que.pop();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &gp[i]);
      if (i <= k + 1) {
        node u;
        u.ind = i;
        u.cost = gp[i];
        que.push(u);
      }
    }
    solve();
  }
  return 0;
}
