#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
set<pair<int, int> > se1;
set<int> se2;
int ans[N];
int main() {
  int n, k, x;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    se1.insert({x, i});
    se2.insert(i + k);
  }
  long long sum = 0;
  for (auto it = se1.rbegin(); it != se1.rend(); it++) {
    auto p = se2.lower_bound(it->second);
    sum += 1ll * (*p - it->second) * it->first;
    ans[it->second] = *p;
    se2.erase(*p);
  }
  printf("%lld\n", sum);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
