#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > pq;
int T[700000];
int ans[400000];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &T[i]);
  }
  long long int tot = 0;
  for (int i = 1; i <= k; i++) pq.push(make_pair(T[i], i));
  for (int i = k + 1; i <= n + k; i++) {
    if (i <= n) pq.push(make_pair(T[i], i));
    int idx = pq.top().second;
    ans[idx] = i;
    tot += (long long int)pq.top().first * (i - idx);
    pq.pop();
  }
  printf("%lld\n", tot);
  for (int i = 1; i <= n; i++) {
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
  }
}
