#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  vector<long long int> cost(n + 1);
  priority_queue<pair<long long int, long long int>> pq;
  long long int cm = 1 + k;
  for (long long int i = 1; i <= n; i++) {
    cin >> cost[i];
    if (i < cm) pq.push({cost[i], i});
  }
  long long int ans = 0;
  map<long long int, long long int> mp;
  for (long long int i = cm; i <= n; i++) {
    pq.push({cost[i], i});
    long long int cst = pq.top().first;
    long long int at = pq.top().second;
    ans += ((cm - at) * cst);
    mp[at] = cm;
    cm++;
    pq.pop();
  }
  while (!pq.empty()) {
    long long int cst = pq.top().first;
    long long int at = pq.top().second;
    ans += ((cm - at) * cst);
    mp[at] = cm;
    cm++;
    pq.pop();
  }
  cout << ans << "\n";
  for (long long int i = 1; i <= n; i++) {
    cout << mp[i] << " ";
  }
}
