#include <bits/stdc++.h>
using namespace std;
int n, k, a;
long long ans, temp;
long long c[300300];
long long memo1[300300];
long long memo2[300300];
long long arr[300300];
priority_queue<pair<long long, int> > pq;
pair<long long, int> cur;
int main() {
  scanf("%d%d", &n, &k);
  memset(arr, -1, sizeof arr);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &c[i]);
    memo1[i] = c[i] * (long long)(k + 1 - (i + 1));
    memo2[i] = c[i] * (long long)(k + n - (i + 1));
  }
  ans = 0;
  for (a = 0; a < min(n, k); a++) {
    pq.push(pair<long long, int>(c[a], a + 1));
  }
  for (int i = 1; i <= n; i++) {
    if (a < n) {
      pq.push(pair<long long, int>(c[a], a + 1));
    }
    a++;
    cur = pq.top();
    pq.pop();
    temp = cur.first * (k + i - cur.second);
    arr[cur.second - 1] = k + i;
    ans += temp;
  }
  printf("%I64d\n", ans);
  for (int i = 0; i < n; i++) {
    printf("%I64d ", arr[i]);
  }
  printf("\n");
  return 0;
}
