#include <bits/stdc++.h>
using namespace std;
long long sum, n, k, t, chk[600005];
struct COST {
  long long ith, bury, time;
};
COST c[600005];
bool cmp(COST c1, COST c2) { return c1.bury > c2.bury; }
bool cmp2(COST c1, COST c2) { return c1.ith < c2.ith; }
void prt() {
  for (int i = 1; i <= n + k; i++) cout << chk[i] << " ";
  cout << endl;
}
int find_empty(int t) {
  if (chk[t])
    return chk[t] = find_empty(chk[t] + 1);
  else
    return chk[t] = t;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i <= k; i++) chk[i] = i;
  for (int i = 0; i < n; i++) {
    cin >> c[i].bury;
    c[i].ith = i + 1;
  }
  sort(c, c + n, cmp);
  for (int i = 0; i < n; i++) {
    t = find_empty(c[i].ith);
    sum += c[i].bury * (t - c[i].ith);
    c[i].time = t;
  }
  sort(c, c + n, cmp2);
  cout << sum << endl;
  for (int i = 0; i < n; i++) cout << c[i].time << " ";
  cout << endl;
  return 0;
}
