#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 1e7 + 5;
inline int read() {
  int res = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    res = (res << 3) + (res << 1) + ch - '0';
    ch = getchar();
  }
  return f ? (~res + 1) : res;
}
long long ans[N];
struct node {
  long long t, w;
  bool operator<(const node &tmp) const {
    return w == tmp.w ? t > tmp.t : w < tmp.w;
  }
  node(long long t = 0, long long w = 0) : t(t), w(w) {}
} now;
priority_queue<node> q;
int main() {
  long long n, k, tmp, result = 0;
  cin >> n >> k;
  for (int i = 1; i <= n + k; i++) {
    if (i <= n) {
      cin >> tmp;
      q.emplace(i, tmp);
    }
    if (i > k) {
      now = q.top();
      q.pop();
      result += now.w * (i - now.t);
      ans[now.t] = i;
    }
  }
  cout << result << endl;
  for (int i = 1; i < n; i++) cout << ans[i] << ' ';
  cout << ans[n] << endl;
  return 0;
}
