#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265359;
const long long int Maxi = 1e18;
multiset<pair<long long, long long> > v;
multiset<pair<long long, long long> >::iterator it;
long long a[300005];
long long b[300005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, i, j, l, k = 0, p = 0, s = 0, t = 1, x, y, z, r, c;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (i <= k + 1) v.insert({a[i], i});
  }
  x = k + 1;
  for (i = 1; i <= n; i++) {
    k++;
    x++;
    it = v.end();
    it--;
    s += (k - it->second) * it->first;
    b[it->second] = k;
    v.erase(it);
    if (x <= n) v.insert({a[x], x});
  }
  cout << s << endl;
  for (i = 1; i <= n; i++) cout << b[i] << " ";
  return 0;
}
