#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long> > q;
vector<long long> v(300005);
int main() {
  long long n, k, ans = 0, i, j;
  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    long long x;
    cin >> x;
    q.push(make_pair(x, i));
  }
  for (int i = k + 1; i <= n; i++) {
    long long x;
    cin >> x;
    q.push(make_pair(x, i));
    long long b = q.top().second;
    long long c = q.top().first;
    q.pop();
    ans += (i - b) * c;
    v[b] = i;
  }
  i = n + 1;
  while (!q.empty()) {
    long long b = q.top().second;
    long long c = q.top().first;
    q.pop();
    ans += (i - b) * c;
    v[b] = i;
    i++;
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << v[i] << " ";
  return 0;
}
