#include <bits/stdc++.h>
using namespace std;
using INT = long long;
const int NN = 300010;
int a[NN], id[NN], ans[NN];
bool cmp(int u, int v) { return a[u] > a[v]; }
set<int> st;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), id[i] = i, st.insert(k + i);
  sort(id + 1, id + n + 1, cmp);
  INT s = 0;
  for (int i = 1; i <= n; i++) {
    int u = id[i];
    auto it = st.lower_bound(u);
    if (it == st.end()) continue;
    int v = *it;
    ans[u] = v;
    s += 1LL * (v - u) * a[u];
    st.erase(it);
  }
  cout << s << endl;
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  cout << endl;
  return 0;
}
