#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 20;
struct node {
  int num;
  long long cost;
  bool operator<(const node &a) const { return cost < a.cost; }
} s[N];
int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    priority_queue<node> q;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &s[i].cost);
      s[i].num = i;
    }
    for (int i = 1; i <= k; ++i) {
      q.push(s[i]);
    }
    long long ans = 0;
    for (int i = k + 1; i <= k + n; ++i) {
      if (i <= n) {
        q.push(s[i]);
      }
      node tmp = q.top();
      q.pop();
      ans += tmp.cost * (i - tmp.num);
      s[tmp.num].num = i;
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; ++i) {
      cout << s[i].num;
      if (i < n) cout << ' ';
    }
    cout << '\n';
  }
  return 0;
}
