#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
const int inf = 0x3f3f3f3f;
struct node {
  long long x;
  int id;
  bool operator<(const node& a) const { return x < a.x; }
} p[maxn];
int ans[maxn];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) == 2) {
    priority_queue<node> q;
    while (!q.empty()) {
      q.pop();
    }
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", &p[i].x);
      p[i].id = i;
      if (i <= k) q.push(p[i]);
    }
    for (int i = k + 1; i <= n; i++) {
      q.push(p[i]);
      node u = q.top();
      q.pop();
      sum += (i - u.id) * u.x;
      ans[u.id] = i;
    }
    for (int i = 1; i <= k; i++) {
      node u = q.top();
      q.pop();
      sum += (i + n - u.id) * u.x;
      ans[u.id] = i + n;
    }
    printf("%I64d\n", sum);
    for (int i = 1; i <= n; i++) {
      if (i == 1)
        printf("%d", ans[i]);
      else
        printf(" %d", ans[i]);
    }
    printf("\n");
  }
}
