#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  priority_queue<pair<int, int> > p;
  set<int> s;
  for (int i = 1; i <= n; i++) {
    int in;
    cin >> in;
    p.push({in, i});
    s.insert(i + k);
  }
  long long ans = 0;
  vector<int> v(n);
  while (p.size()) {
    int c = p.top().first, d = p.top().second;
    p.pop();
    auto it = s.lower_bound(d);
    ans += 1LL * (*it - d) * c;
    v[d - 1] = *it;
    s.erase(it);
  }
  cout << ans << "\n";
  for (auto i : v) cout << i << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve();
  return 0;
}
