#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) {
  int t;
  while (b) {
    a = a % b;
    t = a;
    a = b;
    b = t;
  }
  return a;
}
const int maxn = 1e6 + 8;
struct node {
  int id, val, t;
  friend bool operator<(node a, node b) { return a.val < b.val; }
};
node data[maxn];
bool cmp2(node a, node b) { return a.id < b.id; }
node ans[maxn];
int main() {
  int n, k;
  priority_queue<node> que;
  scanf("%d%d", &n, &k);
  int cnt = 1;
  node x;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &data[i].val);
    data[i].id = i;
    if (i <= k)
      que.push(data[i]);
    else {
      que.push(data[i]);
      x = que.top();
      que.pop();
      x.t = k + cnt;
      ans[cnt] = x;
      cnt++;
    }
  }
  while (!que.empty()) {
    x = que.top();
    que.pop();
    x.t = k + cnt;
    ans[cnt] = x;
    cnt++;
  }
  sort(ans + 1, ans + n + 1, cmp2);
  long long fuck = 0;
  for (int i = 1; i <= n; ++i) {
    fuck += (long long)ans[i].val * (long long)(ans[i].t - ans[i].id);
  }
  printf("%lld\n", fuck);
  for (int i = 1; i < n; ++i) printf("%d ", ans[i].t);
  printf("%d\n", ans[n].t);
  return 0;
}
