#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
ll powmod(ll base, ll exp, const ll MOD) {
  ll ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % MOD;
    base = (base * base) % MOD;
    exp >>= 1;
  }
  return ans;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
const int mxN = 2e5 + 1;
void test_case() {}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> c(n);
  vector<ll> ans(n);
  for (ll i = 0; i < n; ++i) cin >> c[i];
  priority_queue<pair<ll, ll>> pq;
  for (int i = 0; i < min(n, k + 1); ++i) {
    pq.push({c[i], i});
  }
  ll idx = k + 1;
  ll time = k + 1;
  ll res = 0;
  while (!pq.empty()) {
    auto mx = pq.top();
    pq.pop();
    ans[mx.second] = time++;
    if (idx < n) {
      pq.push({c[idx], idx});
      ++idx;
    }
  }
  for (ll i = 0; i < n; ++i) res += (ans[i] - (i + 1)) * c[i];
  cout << res << endl;
  for (auto x : ans) cout << x << " ";
  return 0;
}
