#include <bits/stdc++.h>
using namespace std;
long long n, m, s, t, k, a, b, x, y, u;
const int mod = 1e9 + 7;
const int mxn = 2e5 + 5;
long long mn = 1e18, mx = 0;
long long arr[2000000], wan[2000000], finl[2000000];
string str, str2;
string str4 = "abcdefghijklmnopqrstuvwxyz";
pair<long long, long long> pa[2000000];
set<long long> st;
int main() {
  ios_base::sync_with_stdio(0);
  t = 1;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> x;
      pa[i].first = x;
      pa[i].second = i + 1;
    }
    for (int i = k + 1; i <= n + k; i++) {
      st.insert(i);
    }
    sort(pa, pa + n);
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long num = pa[i].second;
      auto it = st.lower_bound(num);
      if (it == st.end() && it != st.begin()) it--;
      ans += (*it - num) * pa[i].first;
      arr[num - 1] = *it;
      st.erase(*it);
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++) cout << arr[i] << " ";
    cout << endl;
  }
  return 0;
}
