#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}
const int N = 3e5 + 7;
int n, k, T[N], res[N];
priority_queue<pair<int, int> > Q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> T[i];
    if (i <= k + 1) Q.push({T[i], i});
  }
  int nx = k + 1;
  long long ans = 0;
  while (!Q.empty()) {
    ans += (long long)Q.top().first * (nx - Q.top().second);
    res[Q.top().second] = nx++;
    Q.pop();
    if (nx <= n) Q.push({T[nx], nx});
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << res[i] << " ";
  return 0;
}
