#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 300010;
long long N, K;
pair<long long, long long> pr[Maxn];
priority_queue<pair<long long, long long> > Q;
long long z[Maxn];
int main() {
  scanf("%lld%lld", &N, &K);
  for (long long i = 1; i <= N; i++)
    scanf("%lld", &pr[i].first), pr[i].second = i;
  for (long long i = 1; i <= K; i++) Q.push(pr[i]);
  long long ans = 0;
  for (long long i = K + 1; i <= K + N; i++) {
    if (i <= N) Q.push(pr[i]);
    pair<long long, long long> x = Q.top();
    ans += (i - x.second) * x.first;
    z[x.second] = i;
    Q.pop();
  }
  printf("%lld\n", ans);
  for (long long i = 1; i < N; i++) printf("%lld ", z[i]);
  printf("%lld\n", z[N]);
  return 0;
}
