#include <bits/stdc++.h>
using namespace std;
int arr[600005];
priority_queue<pair<long long int, long long int> > pq;
int adi[600005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= k; i++) {
    pq.push(pair<long long int, long long int>(arr[i], i));
  }
  long long int ans = 0;
  for (int i = k + 1; i <= n + k; i++) {
    pq.push(pair<long long int, long long int>(arr[i], i));
    pair<long long int, long long int> pp = pq.top();
    pq.pop();
    ans += (i - pp.second) * (pp.first);
    adi[pp.second] = i;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << adi[i] << " ";
  cout << endl;
  return 0;
}
