#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, k;
int ans[300300];
int c[300300];
priority_queue<pair<int, int> > q;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", c + i);
  for (int i = 0; i < k; i++) q.push(make_pair(c[i], i));
  for (int i = k; i < n; i++) {
    q.push(make_pair(c[i], i));
    pair<int, int> p = q.top();
    q.pop();
    ans[p.second] = i;
  }
  for (int i = n; q.size() > 0; i++) {
    pair<int, int> p = q.top();
    q.pop();
    ans[p.second] = i;
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] < i) assert(false);
    res += (ans[i] - i) * 1ll * c[i];
  }
  printf("%lld\n", res);
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", ans[i] + 1);
  }
  printf("\n");
  return 0;
}
