#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int INF = INT_MAX;
const long long INFLL = (long long)1e18;
const double PI = acos(-1.0);
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T abs(T a) {
  return (a > 0 ? a : -a);
}
const int N = (int)1e5 + 5;
const int P = 1 << 18;
long long n, k, c[N * 3], ans, a[N * 3];
set<pair<long long, long long>> s;
int main() {
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed | ios::showpoint);
  cout.precision(8);
  cin >> n >> k;
  for (int i = 0; i < (n); i++) cin >> c[i];
  for (int i = 0; i < (n + k); i++) {
    if (i < n) s.insert(make_pair(c[i], i));
    if (i < k) continue;
    pair<long long, long long> p = *s.rbegin();
    a[p.second] = i + 1;
    ans += (p.first) * (i - p.second);
    s.erase(p);
  }
  cout << ans << endl;
  for (int i = 0; i < (n); i++) cout << a[i] << ' ';
  return 0;
}
