#include <bits/stdc++.h>
using namespace std;
map<int, int> ma;
set<int> s;
int main() {
  int n, k, c;
  long long int ans = 0;
  cin >> n >> k;
  int arr[n + 1];
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    cin >> c;
    v.push_back(make_pair(c, i + 1));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = k + 1; i <= k + n; i++) {
    s.insert(i);
    ma[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    int x = v[i].second, y = v[i].first;
    if (ma[x]) {
      ma[x] = 0;
      s.erase(x);
      arr[x] = x;
    } else {
      set<int>::iterator it = s.begin();
      ans += (long long int)(*it - x) * (long long int)y;
      ma[*it] = 0;
      s.erase(*it);
      arr[x] = *it;
    }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << arr[i] << " ";
  return 0;
}
