#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int main() {
  int n, k, a[N], out[N];
  long long int ans = 0, now = 0;
  priority_queue<pair<int, int> > pq;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= k; i++) a[i + n] = 0;
  for (int i = 1; i <= k; i++) {
    pq.push(make_pair(a[i], i));
    now += a[i];
    ans += now;
  }
  for (int i = 1; i <= n; i++) {
    pq.push(make_pair(a[i + k], i + k));
    now += a[i + k];
    now -= pq.top().first;
    out[pq.top().second] = i + k;
    pq.pop();
    ans += now;
  }
  printf("%lld\n", ans);
  printf("%d", out[1]);
  for (int i = 2; i <= n; i++) printf(" %d", out[i]);
  printf("\n");
}
