#include <bits/stdc++.h>
using namespace std;
const int maxn = 400005;
int n, m, c[maxn], p[maxn];
long long ans;
priority_queue<pair<int, int> > Heap;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]), ans -= (long long)c[i] * i;
  for (int i = m + 1, now = 0; i <= m + n; i++) {
    while (now < n && now + 1 <= i) now++, Heap.push(make_pair(c[now], now));
    int x = Heap.top().second;
    Heap.pop();
    p[x] = i;
    ans += (long long)c[x] * i;
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
  return 0;
}
