#include <bits/stdc++.h>
using namespace std;
vector<long long> cost;
vector<long long> ans;
long long FINAL[300005];
priority_queue<pair<long long, long long>> pq;
int main() {
  long long counter = 0;
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    cost.push_back(num);
  }
  for (long long i = 0; i < k; i++) {
    pq.push(make_pair(cost[i], i));
  }
  long long i;
  for (i = k; i < n; i++) {
    pq.push(make_pair(cost[i], i));
    pair<long long, long long> P = pq.top();
    pq.pop();
    ans.push_back(P.second);
  }
  while (!pq.empty()) {
    pair<long long, long long> P = pq.top();
    pq.pop();
    ans.push_back(P.second);
  }
  for (long long i = 0; i < ans.size(); i++) {
    FINAL[ans[i]] = i + k + 1;
  }
  for (long long i = 0; i < n; i++) {
    counter += (FINAL[i] - i - 1) * cost[i];
  }
  cout << counter << endl;
  for (long long i = 0; i < n; i++) {
    cout << FINAL[i] << " ";
  }
  return 0;
}
