#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> costs(n);
  for (int i = 0; i < n; i++) {
    cin >> costs[i].first;
    costs[i].second = i;
  }
  sort(costs.rbegin(), costs.rend());
  set<int> s;
  for (int i = k + 1; i <= n + k; i++) {
    s.insert(i - 1);
  }
  vector<int> order(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (s.count(costs[i].second)) {
      order[costs[i].second] = costs[i].second;
      s.erase(s.find(costs[i].second));
    } else {
      order[costs[i].second] = *(s.begin());
      ans += (order[costs[i].second] - costs[i].second) * 1ll * costs[i].first;
      s.erase(s.begin());
      debug() << " ["
              << "ans"
                 ": "
              << (ans) << "] ";
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << ' ';
    cout << order[i] + 1;
  }
  cout << '\n';
  return 0;
}
