#include <bits/stdc++.h>
using namespace std;
class Compare {
 public:
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    if (a.first == b.first) return a.second > b.second;
    return a.first < b.first;
  }
};
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n + 1];
  long long int res[n + 1];
  long long int ans = 0;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >, Compare>
      pq;
  pair<int, int> temp;
  for (long long int i = 1; i <= n; ++i) cin >> arr[i];
  for (long long int i = 1; i <= k; ++i) pq.push({arr[i], i});
  for (long long int i = k + 1; i <= n + k; ++i) {
    if (i <= n) pq.push({arr[i], i});
    temp = pq.top();
    pq.pop();
    ans += (i - temp.second) * temp.first;
    res[temp.second] = i;
  }
  cout << ans << endl;
  for (long long int i = 1; i <= n; ++i) cout << res[i] << " ";
  cout << endl;
}
