#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
inline void read(long long &x) {
  x = 0;
  register char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + (c - '0');
}
inline void write(long long x) {
  register char buffor[35];
  register long long i = 0;
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
inline long long in() {
  long long x;
  read(x);
  return x;
}
void solve();
long long dbg = 1;
using namespace std;
int main() {
  long long t = 1;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
long long a[300005], ans[300005];
set<pair<long long, long long>> se;
set<pair<long long, long long>>::iterator it;
void solve() {
  long long n, k, q = 0;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < k; i++) se.insert(make_pair(a[i], i));
  for (long long i = k; i < k + n; i++) {
    if (i < n) se.insert(make_pair(a[i], i));
    it = se.end();
    it--;
    long long j = (*it).second;
    ans[j] = i;
    q += (i - j) * a[j];
    se.erase(it);
  }
  cout << q << endl;
  for (long long i = 0; i < n; i++) cout << ans[i] + 1 << " ";
  cout << endl;
}
