#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x);
    }
    n >>= 1;
    x = (x * x);
  }
  return res;
}
long long powerMOD(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % 1000000007;
    }
    n >>= 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
bool mycompare(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first > b.first;
}
bool mycompare1(pair<int, int> &a, pair<int, int> &b) {
  return a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long i, j, k, x, n, m, r;
  cin >> n >> k;
  long long ans[n];
  set<pair<long long, long long>> a;
  vector<pair<long long, long long>> b(n);
  for (int i = 0; i < n; i++) {
    cin >> j;
    b[i] = {j, i + 1};
  }
  sort(b.begin(), b.end(), mycompare);
  i = 0;
  x = k + 1;
  long long l = 0;
  while (i < n) {
    if (a.size() == 0) {
      if (b[i].second <= x) {
        ans[b[i].second - 1] = x;
        l += b[i].first * (x - b[i].second);
        x++;
      } else {
        a.insert({b[i].second, b[i].first});
      }
      i++;
    } else {
      if ((*a.begin()).first <= x) {
        ans[((*a.begin()).first) - 1] = x;
        l += ((*a.begin()).second) * (x - ((*a.begin()).first));
        a.erase(*a.begin());
        x++;
      } else if (b[i].second <= x) {
        ans[b[i].second - 1] = x;
        l += b[i].first * (x - b[i].second);
        x++;
        i++;
      } else {
        a.insert({b[i].second, b[i].first});
        i++;
      }
    }
  }
  for (auto z : a) {
    if (z.first > x) {
      ans[z.first - 1] = z.first;
      x = z.first + 1;
      continue;
    }
    ans[z.first - 1] = x;
    l += z.second * (x - z.first);
    x++;
  }
  cout << l << "\n";
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
}
