#include <bits/stdc++.h>
using namespace std;
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  vector<long long> cost(n);
  for (auto(i) = 0; i < n; i++) cin >> cost[i];
  set<pair<long long, long long> > cur;
  for (auto(i) = 0; i < min(n, k + 1); i++) cur.insert(make_pair(cost[i], i));
  long long ans = 0;
  vector<long long> time(n, -1);
  for (auto(curTime) = k + 1; curTime < k + n + 1; curTime++) {
    pair<long long, long long> yay = *(prev(cur.end()));
    long long curMx = yay.first;
    long long curIdx = yay.second;
    ans += curMx * (curTime - curIdx - 1);
    time[curIdx] = curTime;
    if (curTime < n) cur.insert(make_pair(cost[curTime], curTime));
    cur.erase(yay);
  }
  cout << ans << '\n';
  for (auto c : time) cout << c << ' ';
  cout << '\n';
  return 0;
}
