#include <bits/stdc++.h>
using namespace std;
struct asd {
  int id, val;
} node[300010];
bool cmp(asd x, asd y) { return x.val > y.val; }
set<int> st;
set<int>::iterator it;
int ans[300010];
int n, k;
void solve() {
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    it = st.lower_bound(node[i].id);
    ans[node[i].id] = *it;
    res = res + (long long)node[i].val * (*it - node[i].id);
    st.erase(it);
  }
  printf("%I64d\n", res);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &node[i].val);
    node[i].id = i;
  }
  sort(node + 1, node + 1 + n, cmp);
  for (int i = k + 1; i <= n + k; i++) st.insert(i);
  solve();
  return 0;
}
