#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
const int INF = 1e9 + 7;
int c[N];
int t[N];
int main() {
  int n, k;
  cin >> n >> k;
  set<pair<int, int>, greater<pair<int, int>>> q;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    if (i <= k) {
      q.insert({c[i], i});
    }
  }
  for (int i = k + 1; i <= k + n; i++) {
    if (i <= n) {
      q.insert({c[i], i});
    }
    if (q.empty()) {
      break;
    }
    int plane = q.begin()->second;
    t[plane] = i;
    q.erase(q.begin());
  }
  long long cost = 0;
  for (int i = 1; i <= n; i++) {
    cost += 1LL * c[i] * (t[i] - i);
  }
  cout << cost << endl;
  for (int i = 1; i <= n; i++) {
    printf("%d ", t[i]);
  }
  return 0;
}
