#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 100;
const int INF = 0x3f3f3f3f;
int n, k;
int ans[maxn];
struct node {
  long long t, val;
  bool operator<(const node &x) const {
    return val == x.val ? t > x.t : val < x.val;
  }
  node(long long t = 0, long long val = 0) : t(t), val(val) {}
} ttp;
int main() {
  priority_queue<node> q;
  long long tmp, re = 0;
  cin >> n >> k;
  for (int i = 1; i <= n + k; i++) {
    if (i <= n) {
      cin >> tmp;
      q.push(node(i, tmp));
    }
    if (i > k) {
      ttp = q.top();
      q.pop();
      re += ttp.val * (i - ttp.t);
      ans[ttp.t] = i;
    }
  }
  cout << re << endl;
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
