#include <bits/stdc++.h>
using namespace std;
template <class T>
void p(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << endl;
}
int main() {
  int n, k, i;
  cin >> n >> k;
  vector<long long> cost(n);
  for (i = 0; i < n; i++) cin >> cost[i];
  priority_queue<pair<long long, long long> > pq;
  for (i = 0; i < k; i++) pq.push(make_pair(cost[i], -1 * (i)));
  vector<long long> result(n);
  long long total_cost = 0;
  for (long long i = k; i < k + n; i++) {
    if (i < n) pq.push(make_pair(cost[i], -1 * (i)));
    pair<long long, long long> x = pq.top();
    total_cost += (long long)((i + x.second) * x.first);
    pq.pop();
    result[-1 * x.second] = i + 1;
  }
  cout << total_cost << endl;
  p(result);
  return 0;
}
