#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int n, k;
int c[MAXN], ans[MAXN];
vector<pair<int, int> > v[2 * MAXN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", c + i);
    v[max(k + 1, i)].push_back({c[i], i});
  }
  long long res = 0;
  multiset<pair<int, int> > ms;
  for (int i = k + 1; i <= k + n; i++) {
    for (pair<int, int> p : v[i]) ms.insert(p);
    auto it = prev(ms.end());
    pair<int, int> p = *it;
    res += 1ll * (i - p.second) * c[p.second];
    ms.erase(it);
    ans[p.second] = i;
  }
  printf("%lld\n", res);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
