#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int c[N], ans[N];
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", c + i);
  priority_queue<pair<int, int> > pq;
  long long total = 0, r = 0;
  for (int i = 0; i < k; i++) {
    pq.emplace(c[i], i);
    r += c[i];
    total += r;
  }
  int j = k;
  for (int i = 1; i <= n; i++) {
    if (j < n) {
      pq.emplace(make_pair(c[j], j));
      r += c[j];
    }
    int cc, id;
    tie(cc, id) = pq.top();
    pq.pop();
    r -= cc;
    ans[id] = i + k;
    total += r;
    j++;
  }
  cout << total << endl;
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  cout << endl;
  return 0;
}
