#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
priority_queue<pair<int, int> > q;
const int N = 3000007;
int ans[N];
unsigned long long ans1 = 0;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int x;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &x);
    q.push(make_pair(x, i));
  }
  long long a, b;
  for (int i = k + 1; i <= n; i++) {
    scanf("%d", &x);
    q.push(make_pair(x, i));
    a = q.top().first, b = q.top().second;
    ans[b] = i;
    ans1 += (i - b) * a;
    q.pop();
  }
  for (int i = n + 1; i <= n + k; i++) {
    a = q.top().first, b = q.top().second;
    ans[b] = i;
    ans1 += (i - b) * a;
    q.pop();
  }
  printf("%I64d\n", ans1);
  for (int i = 1; i <= n; i++) {
    printf("%d", ans[i]);
    if (i != n) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
  return 0;
}
