#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
long long n, k, ans[N], sum;
struct node {
  long long id, dis;
  bool operator<(const node &x) const { return dis < x.dis; }
} a[N];
priority_queue<node> q;
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i].dis);
    a[i].id = i;
    if (i <= k) q.push(a[i]);
  }
  for (long long i = k + 1; i <= n + k; i++) {
    if (i <= n) q.push(a[i]);
    node tmp = q.top();
    q.pop();
    ans[tmp.id] = i;
    sum += (i - tmp.id) * tmp.dis;
  }
  printf("%lld\n", sum);
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
  return 0;
}
