#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int cost;
  long long int idx;
} a[301000];
bool operator<(const node &a, const node &b) { return a.cost < b.cost; }
int main() {
  long long int n, k, count = 0, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].cost;
    a[i].idx = i + 1;
    sum += a[i].cost * a[i].idx;
  }
  priority_queue<node> q;
  node curr;
  int p = k + 1;
  int i = 0;
  while (i < n) {
    if (a[i].idx <= p) {
      q.push(a[i]);
      i++;
    } else {
      curr = q.top();
      count += p * (curr.cost);
      a[curr.idx - 1].idx = p;
      q.pop();
      p++;
    }
  }
  while (!q.empty()) {
    curr = q.top();
    count += p * (curr.cost);
    a[curr.idx - 1].idx = p;
    q.pop();
    p++;
  }
  cout << count - sum << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i].idx << " ";
  }
  cout << endl;
  return 0;
}
