#include <bits/stdc++.h>
using namespace std;
void inp();
int main() {
  inp();
  return 0;
}
const int N = 4e5;
int a[N], b[N];
class cmp {
 public:
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    if (a.first == b.first) return a.second > b.second;
    return a.first < b.first;
  }
};
priority_queue<pair<long long, long long> > pq;
void inp() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int cur = 1;
  long long ans = 0;
  for (int t = k + 1; t <= k + n; t++) {
    while (cur <= t && cur <= n) {
      pq.push(pair<long long, long long>(a[cur], cur));
      cur++;
    }
    b[pq.top().second] = t;
    ans += pq.top().first * (t - pq.top().second);
    pq.pop();
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d ", b[i]);
  }
}
