#include <bits/stdc++.h>
using namespace std;
struct node {
  long long c;
  int pos;
  bool operator<(const node &a) const {
    if (c == a.c) return pos < a.pos;
    return (c < a.c);
  }
};
node no[300005];
int ran[300005];
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  while (cin >> n >> k) {
    priority_queue<node> q;
    memset(ran, 0, sizeof(ran));
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> no[i].c;
      no[i].pos = i;
    }
    for (int i = 1; i <= k + n; i++) {
      if (i <= n) {
        q.push(no[i]);
      }
      if (i > k) {
        node temp = q.top();
        q.pop();
        ans += (i - temp.pos) * temp.c;
        ran[temp.pos] = i;
      }
    }
    cout << ans << endl;
    for (int i = 1; i < n; i++) {
      cout << ran[i] << " ";
    }
    cout << ran[n] << endl;
  }
  return 0;
}
