#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int arr[N + 100];
vector<pair<long long, int> > v;
set<int> st;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    long long c;
    cin >> c;
    v.push_back(make_pair(c, i));
  }
  for (int i = k + 1; i <= k + n; i++) st.insert(i);
  sort(v.begin(), v.end(), greater<pair<long long, int> >());
  long long ans = 0;
  for (auto it : v) {
    int ind = it.second;
    auto cur = st.lower_bound(ind);
    ans += (*cur - ind) * it.first;
    arr[ind] = *cur;
    st.erase(cur);
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << " ";
  }
  cout << "\n";
}
