#include <bits/stdc++.h>
using namespace std;
struct Flight {
  long long c;
  int t;
  Flight() {}
  Flight(int t, long long c) {
    this->t = t;
    this->c = c;
  }
  bool operator<(const Flight &b) const {
    if (c == b.c) {
      return t > b.t;
    }
    return c < b.c;
  }
};
int n, k;
int ans[2 * 300000 + 1];
int final[300000 + 1];
long long c[300000 + 1];
priority_queue<Flight> pq;
int main() {
  long long cost;
  Flight cur;
  int i;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%lld", c + i);
    pq.push(Flight(i, c[i]));
  }
  cost = 0;
  for (i = k + 1; i <= k + n;) {
    if (pq.empty()) {
      break;
    }
    cur = pq.top();
    pq.pop();
    while (ans[i]) {
      i++;
    }
    if (i < cur.t) {
      ans[cur.t] = cur.t;
      final[cur.t] = cur.t;
    } else {
      ans[i] = cur.t;
      cost += (i - cur.t) * cur.c;
      final[cur.t] = i;
    }
  }
  printf("%lld\n", cost);
  for (i = 1; i < n; i++) {
    printf("%d ", final[i]);
  }
  printf("%d\n", final[i]);
  return 0;
}
