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