#include <bits/stdc++.h>
struct plane {
  long long int time;
  long long int delaycost;
};
bool operator<(const plane& a, const plane& b) {
  return a.delaycost < b.delaycost;
}
long long int out[300001];
int main(void) {
  std::vector<plane> result;
  std::priority_queue<plane, std::vector<plane>, std::less<plane>> pq;
  int n, k;
  while (std::cin >> n >> k) {
    for (int i = 1; i <= k + 1 && i <= n; i++) {
      plane temp;
      std::cin >> temp.delaycost;
      temp.time = i;
      pq.push(temp);
    }
    for (int i = k + 2; i <= n; i++) {
      result.push_back(pq.top());
      pq.pop();
      plane temp;
      std::cin >> temp.delaycost;
      temp.time = i;
      pq.push(temp);
    }
    while (!pq.empty()) {
      result.push_back(pq.top());
      pq.pop();
    }
    long long int total = 0;
    for (auto iter = result.begin(); iter != result.end(); iter++) {
      out[iter->time] = k + iter - result.begin() + 1;
      total = total +
              (iter->delaycost) * (k + iter - result.begin() + 1 - iter->time);
    }
    std::cout << total << '\n';
    for (auto i = 1; i <= n; i++) {
      if (i != 1) std::cout << ' ';
      std::cout << out[i];
    }
    std::cout << '\n';
  }
}
