#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 300000 + 5;
long long t[maxn];
struct node {
  int value, in;
};
node c[maxn];
struct cmp {
  bool operator()(node x, node y) { return x.value < y.value; }
};
priority_queue<node, vector<node>, cmp> q;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i].value);
    c[i].in = i;
    if (i <= k - 1) q.push(c[i]);
  }
  long long total = 0;
  long long time = k + 1;
  while (!q.empty()) {
    if (time <= n) {
      q.push(c[time - 1]);
    }
    int ind = q.top().in;
    q.pop();
    t[ind] = time;
    total += (t[ind] - (ind + 1)) * c[ind].value;
    time++;
  }
  cout << total << endl;
  for (int i = 0; i < n; i++) {
    cout << t[i] << " ";
  }
  return 0;
}
