#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, val;
  node(int a, int b) { x = a, val = b; }
  friend bool operator<(node a, node b) { return a.val < b.val; }
};
int n, m;
int a[300030];
int ans[300030];
long long sum = 0;
priority_queue<node> q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m && i <= n; i++) {
    q.push(node(i, a[i]));
  }
  int now = m + 1;
  for (int i = 1; i <= n; i++) {
    if (now <= n) q.push(node(now, a[now]));
    node t = q.top();
    q.pop();
    ans[t.x] = now;
    sum += (long long)(now - t.x) * t.val;
    now++;
  }
  cout << sum << endl;
  printf("%d", ans[1]);
  for (int i = 2; i <= n; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  return 0;
}
