#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<long long, int> > a;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.push_back(make_pair(x, i + 1));
  }
  vector<int> m(2 * n + 10, 1);
  sort(a.begin(), a.end());
  vector<int> ans(n + 1);
  long long sum = 0;
  long long first = k + 1;
  for (int i = a.size() - 1; i >= 0; --i) {
    long long x = a[i].first;
    long long y = a[i].second;
    if (y > k && m[y]) {
      m[y] = 0;
      ans[y] = y;
    } else {
      m[first] = 0;
      sum += (x * (first - y));
      ans[y] = first;
    }
    while (!m[first]) {
      ++first;
    }
  }
  cout << sum << endl;
  for (int i = 1; i < ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
