#include <bits/stdc++.h>
using namespace std;
struct node {
  int id, cost;
  bool operator<(node Q) const {
    if (Q.cost != cost) return Q.cost > cost;
    return id < Q.id;
  }
} mon;
priority_queue<node> Q;
int a[400000], ans[400000];
int main() {
  node c;
  int n, k;
  long long ans1, cos;
  cin >> n >> k;
  ans1 = 0;
  cos = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k; i++) {
    c.cost = a[i];
    c.id = i;
    Q.push(c);
    cos += c.cost;
    ans1 += cos;
  }
  for (int i = k + 1; i <= n; i++) {
    c.cost = a[i];
    c.id = i;
    Q.push(c);
    cos += c.cost;
    c = Q.top();
    Q.pop();
    ans[c.id] = i;
    cos -= c.cost;
    ans1 += cos;
  }
  for (int i = n + 1; i <= n + k; i++) {
    c = Q.top();
    Q.pop();
    ans[c.id] = i;
    cos -= c.cost;
    ans1 += cos;
  }
  cout << ans1 << endl;
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
