#include <bits/stdc++.h>
using namespace std;
const int mx = 100100;
int main() {
  int n, k, x;
  set<int> st;
  set<int>::iterator it;
  vector<pair<int, int> > arr, ars;
  long long ans = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < n; i += 1) {
    scanf("%d", &x);
    arr.push_back(make_pair(x, i));
    st.insert(k + i + 1);
  }
  sort(arr.begin(), arr.end());
  for (int i = n - 1; i >= 0; i -= 1) {
    it = st.lower_bound(arr[i].second + 1);
    ans += (long long)arr[i].first * (abs((arr[i].second + 1) - *it));
    ars.push_back(make_pair(arr[i].second, *it));
    st.erase(*it);
  }
  printf("%I64d\n", ans);
  sort(ars.begin(), ars.end());
  for (int i = 0; i < ars.size(); i += 1) {
    printf("%d", ars[i].second);
    if (i != ars.size() - 1) printf(" ");
  }
  printf("\n");
}
