#include <bits/stdc++.h>
using namespace std;
struct plain {
  int n;
  long long c;
  bool operator<(const plain& rhs) const { return c > rhs.c; }
} a[300010];
set<int> s;
long long ans = 0;
int n, k;
int p[300010];
int main() {
  cin >> n >> k;
  for (int i = k + 1; i <= k + n; i++) s.insert(i);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].c;
    a[i].n = i;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    auto now = s.lower_bound(a[i].n);
    if (now == s.end()) now--;
    ans += (*now - a[i].n) * a[i].c;
    p[a[i].n] = *now;
    s.erase(now);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  cout << endl;
  return 0;
}
