#include <bits/stdc++.h>
using namespace std;
set<int> s;
long long ans;
int n, k, a[301000], b[301000];
bool cmp(const int &o, const int &p) { return a[o] > a[p]; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = k; i < n + k; ++i) {
    s.insert(i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    b[i] = i;
  }
  sort(b, b + n, cmp);
  for (int I = 0; I < n; ++I) {
    int i = b[I];
    int pos = *s.lower_bound(i);
    s.erase(pos);
    ans += 1LL * a[i] * (pos - i);
    a[i] = pos;
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    printf("%d%c", a[i] + 1, " \n"[i + 1 == n]);
  }
  return 0;
}
