#include <bits/stdc++.h>
using namespace std;
const int MX = 300005;
int cost[MX];
int ans[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  while (cin >> n >> k) {
    for (int i = (1); i <= (n); i++) cin >> cost[i];
    priority_queue<pair<int, int>, vector<pair<int, int>>> pq;
    for (int i = (1); i <= (k + 1); i++) {
      pq.push(make_pair(cost[i], i));
    }
    int i = k + 1;
    long long w = 0LL;
    while (!pq.empty()) {
      pair<int, int> cur = pq.top();
      int cst = cur.first;
      int id = cur.second;
      ans[id] = i;
      w += 1LL * cst * 1LL * (i - id);
      pq.pop();
      i++;
      if (i <= n) {
        pq.push(make_pair(cost[i], i));
      }
    }
    cout << w << "\n";
    cout << ans[1];
    for (int j = (2); j <= (n); j++) {
      cout << " " << ans[j];
    }
    cout << "\n";
  }
  return 0;
}
