#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> c(n);
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> c[i];
  }
  long long int ans = 0, sum = 0;
  priority_queue<pair<long long int, long long int> > g;
  for (long long int i = 0; i <= k - 1; i++) {
    ans += sum;
    sum += c[i];
    g.push({c[i], i});
  }
  vector<long long int> t(n);
  for (long long int i = k; i <= k + n - 1; i++) {
    pair<long long int, long long int> mx = g.top();
    if (i < n && mx.first >= c[i]) {
      ans += sum;
      t[mx.second] = i + 1;
      sum -= mx.first;
      sum += c[i];
      g.pop();
      g.push({c[i], i});
    } else if (i >= n) {
      ans += sum;
      t[mx.second] = i + 1;
      sum -= mx.first;
      g.pop();
    } else {
      t[i] = i + 1;
      ans += sum;
    }
  }
  cout << ans << endl;
  for (long long int i = 0; i <= n - 1; i++) {
    cout << t[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
