#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const { return x < a.x; }
};
P v[5055];
int a, b, c, n, m, i, o[620000], k, d, e, dy[15] = {0, 0, -1, 1, -1, 1, -1, 1},
                                          dx[15] = {-1, 1, 0, 0, 1, 1, -1, -1};
int l[610011];
long long x, y, z[10055];
P u[600200];
int j[105244];
priority_queue<P> q, q1;
stack<int> s;
map<int, int> p;
string r, r1;
bool as(P a, P b) { return a.x > b.x; }
int f(int a, int b) {
  if (a < b) swap(a, b);
  for (; b;) {
    int h = a;
    a = b;
    b = h % b;
  }
  return a;
}
int main() {
  scanf("%d %d", &a, &b);
  for (int t = 1; t <= a; t++) {
    scanf("%d", &u[t].x);
    u[t].y = t;
  }
  for (int t = 1; t <= b; t++) q.push({u[t].x, u[t].y});
  for (int t = b + 1; t <= a + b; t++) {
    if (t <= a) q.push({u[t].x, u[t].y});
    x += (long long)(t - q.top().y) * q.top().x;
    l[q.top().y] = t;
    q.pop();
  }
  printf("%lld\n", x);
  for (int t = 1; t <= a; t++) printf("%d ", l[t]);
}
