#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long int, long long int> > p_que;
long long int arr[300005];
long long int ans[300005];
int main(int argc, char const *argv[]) {
  long long int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= k; i++) {
    p_que.push(make_pair(arr[i], i));
  }
  long long int tot = 0;
  for (int i = k + 1; i <= n + k; i++) {
    if (i <= n) p_que.push(make_pair(arr[i], i));
    pair<long long int, long long int> p = p_que.top();
    p_que.pop();
    tot = tot + (i - p.second) * p.first;
    ans[p.second] = i;
  }
  cout << tot << "\n";
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
