#include <bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) { return _a < _b ? _a : _b; }
inline int max(int _a, int _b) { return _a > _b ? _a : _b; }
template <class T>
inline void rd(T &_a) {
  int _f = 0, _ch = getchar();
  _a = 0;
  while (_ch < '0' || _ch > '9') {
    if (_ch == '-') _f = 1;
    _ch = getchar();
  }
  while (_ch >= '0' && _ch <= '9') {
    _a = (_a << 1) + (_a << 3) + _ch - '0';
    _ch = getchar();
  }
  if (_f) _a = -_a;
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int c[300005], p[300005];
priority_queue<pair<int, int> > q;
int main() {
  int n, k;
  long long ans = 0;
  rd(n);
  rd(k);
  for (int i = 1; i <= n; i++) rd(c[i]);
  for (int i = 1; i <= k; i++) q.push(make_pair(c[i], i));
  for (int i = k + 1; i <= k + n; i++) {
    if (i <= n) q.push(make_pair(c[i], i));
    pair<int, int> u = q.top();
    q.pop();
    p[u.second] = i;
    ans += (long long)(i - u.second) * u.first;
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
  return 0;
}
