#include <bits/stdc++.h>
using namespace std;
const int max_n = 3e5 + 5;
struct takhir {
  long long value;
  int index;
};
int n, k;
takhir c[max_n];
void printSet(multiset<int, std::greater<int>> st) {
  for (auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << " ";
  cout << endl;
}
int operator<(const takhir &t1, const takhir &t2) {
  return (t1.value < t2.value);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> c[i].value;
    c[i].index = i;
  }
  priority_queue<takhir> cands;
  long long set_sum = 0;
  for (int i = 0; i < min(k + 1, n); i++) {
    set_sum += c[i].value;
    cands.push(c[i]);
  }
  int c_itr = min(k + 1, n);
  vector<long long> answers(n, 0);
  long long answer = 0;
  for (int i = 0; i < min(k, n); i++) answer += (k - i) * c[i].value;
  int currentTime = k + 1;
  while (!cands.empty()) {
    takhir cands_max = cands.top();
    answers[cands_max.index] = currentTime;
    currentTime++;
    set_sum -= cands_max.value;
    answer += set_sum;
    cands.pop();
    if (c_itr < n) {
      set_sum += c[c_itr].value;
      cands.push(c[c_itr]);
      c_itr++;
    }
  }
  cout << answer << endl;
  for (auto temp : answers) cout << temp << ' ';
  cout << endl;
  return 0;
}
