#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, k, c[MAXN];
set<int> s;
pair<int, int> b[MAXN];
int res[MAXN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    b[i] = {c[i], i};
    s.insert(k + i + 1);
  }
  long long ans = 0;
  sort(b, b + n, greater<pair<int, int>>());
  for (int i = 0; i < n; i++) {
    int id = b[i].second;
    int j = *s.lower_bound(id + 1);
    ans += 1ll * (j - id - 1) * 1ll * c[id];
    s.erase(j);
    res[id] = j;
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
}
