#include <bits/stdc++.h>
using namespace std;
long long LINF = std::numeric_limits<long long>::max();
int INF = std::numeric_limits<int>::max();
int main() {
  int testCases = 1;
  for (int j = 0; j < testCases; j++) {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> input(n);
    vector<int> result(n);
    for (int i = 0; i < n; i++) {
      cin >> input[i].first;
      input[i].second = i;
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>>
        minHeap;
    for (int i = 0; i < k; i++) minHeap.push(input[i]);
    int i = 0;
    while (!minHeap.empty()) {
      if (k + i < n) minHeap.push(input[k + i]);
      ++i;
      pair<int, int> entry = minHeap.top();
      minHeap.pop();
      result[entry.second] = k + i;
    }
    long long totalCost = 0;
    for (int i = 0; i < n; i++) {
      long long firstHalf = result[i] - i - 1;
      long long secondHalf = input[i].first;
      totalCost += firstHalf * secondHalf;
    }
    cout << totalCost << endl;
    for (int i = 0; i < n; i++) {
      cout << result[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
