#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int inf = (int)1e9 + 7;
const long long INF = (long long)2e18 + 7;
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 7;
int n, k, a[N], t[N];
long long ans;
set<pair<int, int> > second;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i <= k) second.insert(make_pair(a[i], i));
  }
  for (int i = k + 1; i <= n + k; i++) {
    if (i <= n) second.insert(make_pair(a[i], i));
    int maxi = second.rbegin()->second;
    second.erase((--second.end()));
    t[maxi] = i;
    ans += (i - maxi) * 1ll * a[maxi];
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; i++) cout << t[i] << ' ';
  return 0;
}
