#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, k, p[6000010];
set<int> vis;
pair<int, int> a[6000010];
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    a[i].first = read();
    a[i].second = i;
    vis.insert(i + k);
  }
  sort(a + 1, a + 1 + n);
  reverse(a + 1, a + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    auto w = vis.lower_bound(a[i].second);
    ans += (*w - a[i].second) * (long long)a[i].first;
    p[a[i].second] = *w;
    vis.erase(*w);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  return 0;
}
