#include <bits/stdc++.h>
const long long int LL_INF = 0x3f3f3f3f3f3f;
const long long int MOD = 1073741824;
using namespace std;
int T;
int n, m, k;
int inp;
string arr[1000005];
set<int> st;
vector<pair<int, int> > v;
map<int, int> mp;
string str;
struct cmp {
  template <typename T, typename U>
  bool operator()(T const& lhs, U const& rhs) const {
    if (lhs.first < rhs.first) return true;
    if (rhs.first < lhs.first) return false;
    return lhs.second < rhs.second;
  }
};
priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> pq;
void gen() {}
void solve() {
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &inp);
    pair<int, int> curr = {inp, i + 1};
    v.push_back(curr);
    if (i < k) pq.push(curr);
  }
  long long int ans = 0;
  int res[300005];
  int curr = k + 1;
  for (int i = k; i < n; ++i) {
    pq.push(v[i]);
    ans +=
        (long long int)(curr - pq.top().second) * (long long int)pq.top().first;
    res[pq.top().second - 1] = curr;
    curr++;
    pq.pop();
  }
  while (!pq.empty()) {
    ans +=
        (long long int)(curr - pq.top().second) * (long long int)pq.top().first;
    res[pq.top().second - 1] = curr;
    curr++;
    pq.pop();
  }
  printf("%lld\n", ans);
  for (int i = 0; i < n; ++i) {
    printf("%d ", res[i]);
  }
}
int main() {
  T = 1;
  for (int i = 0; i < T; ++i) solve();
  printf("\n");
  return 0;
}
