#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
struct node {
  int val, id;
  bool operator<(const node &o) const { return val > o.val; }
} a[maxn];
int n, k, c[maxn];
int pos[maxn << 1];
set<int> st;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", c + i);
    a[i] = node{c[i], i};
    st.insert(i + k);
  }
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    auto ipo = st.lower_bound(a[i].id);
    ans += 1ll * a[i].val * (*ipo - a[i].id);
    pos[a[i].id] = *ipo;
    st.erase(ipo);
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d ", pos[i]);
  }
  return 0;
}
