#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[300300];
priority_queue<pair<long long, int> > q;
int cnt;
long long ans = 0;
int ans2[300300];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  int i;
  for (i = 1; i <= k; i++) q.push(make_pair(c[i], i));
  cnt = k + 1;
  while (q.size()) {
    if (i <= n) q.push(make_pair(c[i], i)), i++;
    ans += (long long)(q.top().first * (cnt - q.top().second));
    ans2[q.top().second] = cnt;
    q.pop();
    cnt++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << ans2[i] << " ";
  return 0;
}
