#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main() {
  priority_queue<pair<int, int>, vector<pair<int, int> > > pq;
  vector<pair<int, int> > v;
  vector<pair<int, int> > ans;
  long long n, k, i, first;
  cin >> n >> k;
  long long s = 0;
  for (i = 0; i < n; i++) {
    cin >> first;
    v.push_back(make_pair(first, i));
    if (i < k) pq.push(v[i]);
  }
  for (i = k; i < v.size(); i++) {
    pair<int, int> t;
    t = pq.top();
    if (t.first > v[i].first) {
      s += ((i - t.second) * (t.first));
      ans.push_back(make_pair(t.second, i));
      pq.pop();
      pq.push(v[i]);
    } else
      ans.push_back(make_pair(v[i].second, i));
  }
  while (!pq.empty()) {
    pair<int, int> t = pq.top();
    pq.pop();
    s += ((i - t.second) * (t.first));
    ans.push_back(make_pair(t.second, i));
    i++;
  }
  cout << s << endl;
  sort(ans.begin(), ans.end(), cmp);
  for (i = 0; i < ans.size(); i++) {
    cout << ans[i].second + 1 << " ";
  }
  return 0;
}
