#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > Set;
int ans[610000], c[610000], n, k;
long long Ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= min(n, k); i++) Set.insert(make_pair(-c[i], i));
  for (int i = k + 1; i <= n + k; i++) {
    if (i <= n) Set.insert(make_pair(-c[i], i));
    ans[Set.begin()->second] = i;
    Set.erase(Set.begin());
  }
  for (int i = 1; i <= n; i++) Ans += 1LL * c[i] * (ans[i] - i);
  cout << Ans << endl;
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
