#include <bits/stdc++.h>
using namespace std;
set<long long> se;
pair<long long, int> a[300000];
int vans[300000];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
    se.insert(i + 1 + k);
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto it = se.lower_bound(a[i].second);
    long long kek = *it;
    se.erase(it);
    vans[a[i].second - 1] = kek;
    ans += (kek - a[i].second) * a[i].first;
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) cout << vans[i] << ' ';
  cout << '\n';
  return 0;
}
