#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  vector<long long> c(N);
  for (int i = 0; i < N; i++) cin >> c[i];
  long long ansval = 0;
  vector<long long> ans(N);
  priority_queue<pair<long long, long long> > que;
  for (int timer = 0; timer < K + N; timer++) {
    if (timer < N) {
      que.push({c[timer], timer});
    }
    if (timer >= K) {
      auto tmp = que.top();
      que.pop();
      ans[tmp.second] = timer;
      ansval += tmp.first * (timer - tmp.second);
    }
  }
  cout << ansval << "\n";
  for (int i = 0; i < N; i++) {
    cout << ans[i] + 1 << " ";
  }
  cout << "\n";
  return 0;
}
