#include <bits/stdc++.h>
using namespace std;
long long n, k, a[300001], ta, tc, rv[300001];
set<pair<long long, long long>> dc;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k && i <= n; i++) dc.insert(make_pair(a[i], i));
  ta = k;
  for (int i = 1; i <= n; i++) {
    ta++;
    if (ta <= n) dc.insert(make_pair(a[ta], ta));
    tc += (*dc.rbegin()).first * (ta - (*dc.rbegin()).second);
    rv[(*dc.rbegin()).second] = ta;
    dc.erase(std::prev(dc.end()));
  }
  cout << tc << '\n';
  for (int i = 1; i <= n; i++) cout << rv[i] << " ";
  return 0;
}
