#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void Time() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const int INF = 1e9 + 7;
long double pi = 3.1415926535897932;
const long long INF64 = 9e18;
const long long mod = 1e9 + 7;
const int mxN = 2e5;
const int nxN = 2000;
map<pair<long long, long long>, long long> mp;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; ++i) {
    int c;
    cin >> c;
    v.push_back({c, i + 1});
  }
  long long l = k + 1;
  sort(v.rbegin(), v.rend());
  int mark[n + k + 10];
  long long ans = 0;
  vector<int> given(n + 2, 0);
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < n; ++i) {
    long long f = v[i].first, s = v[i].second;
    if (mark[s] || s <= k) {
      while (mark[l]) l++;
      ans += (l - s) * f;
      given[s] = l;
      mark[l] = true;
    } else
      mark[s] = true, given[s] = s;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; ++i) cout << given[i] << " ";
  cout << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.precision(15);
  cout.precision(15);
  cerr << fixed;
  cout << fixed;
  int t;
  solve();
  Time();
  return 0;
}
