#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  struct num {
    int cost, idx;
  };
  vector<num> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].cost;
    v[i].idx = i + 1;
  }
  sort(v.rbegin(), v.rend(), [&](const num &lhs, const num &rhs) {
    if (lhs.cost == rhs.cost) {
      return lhs.idx < rhs.idx;
    }
    return lhs.cost < rhs.cost;
  });
  set<int> unused;
  for (int i = 1; i <= n; ++i) {
    unused.insert(i + k);
  }
  long long ans = 0;
  vector<int> ans_(v.size(), 0);
  for (int i = 0; i < v.size(); ++i) {
    if (unused.count(v[i].idx) == 1) {
      unused.erase(v[i].idx);
      ans_[v[i].idx - 1] = v[i].idx;
    } else {
      long long cur = *(unused.upper_bound(v[i].idx));
      ans += (cur - v[i].idx) * v[i].cost;
      ans_[v[i].idx - 1] = cur;
      unused.erase(cur);
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < ans_.size(); ++i) {
    cout << ans_[i] << ' ';
  }
}
