#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, z;
  cin >> n >> k;
  vector<pair<int, int>> h, res;
  h.reserve(n);
  h.resize(k);
  for (int i = 0; i < k; ++i) {
    cin >> h[i].first;
    h[i].second = i;
  }
  make_heap(begin(h), end(h));
  res.reserve(n);
  int64_t total = 0;
  for (int i = k; i < n; ++i) {
    cin >> z;
    h.emplace_back(z, i);
    push_heap(begin(h), end(h));
    auto& p = h.front();
    total += p.first * (int64_t)(i - p.second);
    res.emplace_back(p.second, i);
    pop_heap(begin(h), end(h));
    h.pop_back();
  }
  for (int i = n; !h.empty(); ++i) {
    auto& p = h.front();
    total += p.first * (int64_t)(i - p.second);
    res.emplace_back(p.second, i);
    pop_heap(begin(h), end(h));
    h.pop_back();
  }
  sort(begin(res), end(res));
  cout << total << endl << res[0].second + 1;
  for (int i = 1; i < n; ++i) cout << ' ' << res[i].second + 1;
  cout << endl;
}
