#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
  long long int n, k, i, s, a1, b;
  while (cin >> n >> k) {
    long long int a[n + 5], w[n + 5];
    priority_queue<pair<long long int, long long int> > pq;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= k; i++) pq.push(make_pair(a[i], i));
    s = 0;
    for (i = k + 1; i <= n + k; i++) {
      if (i <= n) pq.push(make_pair(a[i], i));
      a1 = pq.top().first;
      b = pq.top().second;
      s = s + (i - b) * a1;
      w[b] = i;
      pq.pop();
    }
    cout << s << endl;
    for (i = 1; i <= n; i++) cout << w[i] << " ";
    cout << endl;
  }
  return 0;
}
