#include <bits/stdc++.h>
using namespace std;
const double epsilon = 0.0000001;
const int mod = 1000000007;
double pi = 2 * acos(0.0);
vector<int> V[1];
vector<int> K[1];
bool flag[1];
int xe, y;
int gcd(int a, int b, int &x, int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  int x1, y1;
  int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
int gcd(long long a, long long b) { return a % b == 0 ? b : gcd(b % a, a); }
long long cnt;
void DFS(int U) {
  int i;
  if (flag[U]) return;
  flag[U] = true;
  for (i = 0; i < V[U].size(); i++) DFS(V[U][i]);
  cnt--;
}
long long soch(long long n, long long k) {
  int s = n % mod;
  for (int i = n - 1; i >= n - k + 1; i--) s = (s * i) % mod;
  for (int i = 2; i <= k; i++) {
    gcd(i, mod, xe, y);
    s *= (xe % mod + mod) % mod;
  }
  return s % mod;
}
list<pair<int, int> > A;
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
int B[700000];
int ans[300300];
int main() {
  srand(time(NULL));
  long long n, k;
  cin >> n >> k;
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    A.push_back(make_pair(a, i + 1));
  }
  cout << endl;
  A.sort(comp);
  int cnt = k + 1;
  int deleted = 0;
  auto it = A.begin();
  while (it != A.end() || deleted > 0) {
    if (it != A.end() && cnt - deleted < it->second) {
      deleted++;
      B[it->second] = it->first;
      it = A.erase(it);
      cnt++;
      while (B[cnt - deleted]) {
        if (it != A.end())
          A.insert(it, make_pair(B[cnt - deleted], cnt - deleted));
        else
          A.push_back(make_pair(B[cnt - deleted], cnt - deleted));
        B[cnt - deleted] = 0;
        deleted--;
      }
      continue;
    }
    while (B[cnt - deleted]) {
      if (it != A.end())
        A.insert(it, make_pair(B[cnt - deleted], cnt - deleted));
      else
        A.push_back(make_pair(B[cnt - deleted], cnt - deleted));
      B[cnt - deleted] = 0;
      deleted--;
    }
    if (it != A.end()) cnt++;
    if (it != A.end()) it++;
  }
  cnt = k + 1;
  deleted = 0;
  it = A.begin();
  cnt = k + 1;
  long long sum = 0;
  for (auto i = A.begin(); i != A.end(); i++) {
    ans[i->second] = cnt;
    sum += (long long)((long long)cnt - i->second) * i->first;
    cnt++;
  }
  cout << sum << endl;
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
