#include <bits/stdc++.h>
using namespace std;
bool desc(long long i, long long j) { return i > j; }
long long power(long long x, long long n) {
  if (n == 0 || x == 0)
    return 1;
  else if (n % 2 == 0)
    return power((x * x) % 1000000007, n / 2);
  else
    return (x * power((x * x) % 1000000007, (n - 1) / 2)) % 1000000007;
}
long long fac[1000009], ar[1000009], out[1000009];
bool prime01[1000009], mark[10000];
void fact() {
  fac[0] = 1;
  for (long long i = 1; i < 1000009; i++) fac[i] = (i * fac[i - 1]);
}
void sieve(long long m) {
  memset(prime01, 1, sizeof(prime01));
  prime01[1] = 0;
  prime01[0] = 0;
  for (long long p = 2; p * p < m; p++) {
    if (prime01[p]) {
      for (long long i = p * 2; i < m; i += p) prime01[i] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long i, j, k, n, m, test, ans, a, b, t;
  string s;
  test = 1;
  while (test--) {
    cin >> n >> k;
    std::vector<pair<long long, long long> > v;
    for (i = 1; i <= n; i++) {
      cin >> ar[i];
      v.push_back({ar[i], i});
    }
    sort(v.begin(), v.end());
    map<long long, long long> vis;
    ans = 0;
    set<long long> ss;
    for (i = k + 1; i <= k + n; i++) ss.insert(i);
    for (i = n - 1; i >= 0; i--) {
      j = max(v[i].second, k + 1);
      auto it = ss.lower_bound(j);
      out[v[i].second] = *it;
      ans += (*it - v[i].second) * v[i].first;
      ss.erase(it);
    }
    cout << ans << "\n";
    for (i = 1; i <= n; i++) cout << out[i] << " ";
  }
  return 0;
}
