#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k;
int a[N], res[N];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  priority_queue<pair<int, int> > q;
  for (int i = 1; i <= k; i++) q.push({a[i], i});
  long long ans = 0;
  for (int i = k + 1; i <= k + n; i++) {
    if (i <= n) q.push({a[i], i});
    auto x = q.top();
    q.pop();
    ans += (long long)(i - x.second) * x.first;
    res[x.second] = i;
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", res[i]);
  puts("");
  return 0;
}
