#include <bits/stdc++.h>
const int N = 3e5 + 5;
using namespace std;
int n, k, ans[N];
pair<int, int> c[N];
set<pair<int, int> > fl;
long long cost;
int main() {
  scanf(" %d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf(" %d", &c[i].first);
    c[i].second = i;
  }
  int l = 1;
  for (int i = k + 1; i <= n + k; i++) {
    while (c[l].second <= i && l <= n) fl.insert(c[l++]);
    pair<int, int> next = *fl.rbegin();
    ans[next.second] = i;
    cost += 1LL * (i - next.second) * next.first;
    fl.erase(next);
  }
  printf("%lld\n", cost);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
