#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  set<int> second;
  for (int i = k + 1; i <= k + n; i++) second.insert(i);
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back({x, i + 1});
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  int pos[n + 1];
  for (int i = v.size() - 1; i >= 0; i--) {
    int p = v[i].second;
    set<int>::iterator it;
    it = second.lower_bound(p);
    ans += 1LL * (*it - p) * v[i].first;
    pos[p] = *it;
    second.erase(it);
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << pos[i] << " ";
  return 0;
}
