#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int p[N], new_p[N];
long long c[N];
set<int> S;
bool cmp(int i, int j) { return c[i] > c[j]; }
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    cin >> c[i];
    S.insert(i + k);
  }
  sort(p + 1, p + n + 1, cmp);
  long long min_cost = 0;
  for (int i = 1; i <= n; i++) {
    int index = p[i];
    new_p[index] = *S.lower_bound(index);
    S.erase(new_p[index]);
    min_cost += c[index] * (new_p[index] - index);
  }
  cout << min_cost << endl;
  for (int i = 1; i <= n; i++) cout << new_p[i] << " ";
  cout << endl;
  return 0;
}
