#include <bits/stdc++.h>
using namespace std;
bool vis[700005];
int a[700005];
int ans[700005];
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> vec;
  for (int i = 1; i <= n; i++) cin >> a[i];
  set<pair<int, int>> se;
  long long res = 0;
  for (int i = 1; i <= n + k; i++) {
    if (a[i]) se.insert(pair<int, int>(a[i], i));
    if (i > k) {
      auto mx = *se.rbegin();
      se.erase(*se.rbegin());
      ans[mx.second] = i;
      res += 1LL * (i - mx.second) * mx.first;
    }
  }
  assert(se.size() == 0);
  cout << res << "\n";
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
