#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int ans[maxn];
struct node {
  int cost, id;
  bool operator<(const node &a) const { return cost < a.cost; }
} s[maxn];
priority_queue<node> que;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i].cost;
    s[i].id = i;
  }
  long long res = 0;
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    while (cnt <= n && s[cnt].id <= i + k) {
      que.push(s[cnt]);
      cnt++;
    }
    node t = que.top();
    que.pop();
    ans[t.id] = i + k;
    res += 1ll * (i + k - t.id) * t.cost;
  }
  cout << res << endl;
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
