#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char ch) {
  ch = tolower(ch);
  return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
inline bool isprime(int n) {
  if (n < 2 || (n % 2 == 0 && n != 2)) return false;
  for (int i = 3; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
class Union {
 private:
  vector<int> saizu, link;

 public:
  Union(int n) {
    saizu.assign(n, 1);
    link.resize(n);
    iota(link.begin(), link.end(), 0);
  }
  int find(int n) {
    if (link[n] == n) return n;
    return link[n] = find(link[n]);
  }
  int same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    if (same(a, b)) return;
    a = find(a);
    b = find(b);
    if (saizu[a] < saizu[b]) swap(a, b);
    saizu[a] += saizu[b];
    link[b] = a;
  }
  int getsize(int a) { return saizu[find(a)]; }
};
const int mod = 1e9 + 7;
long long mode(long long a) {
  a %= mod;
  if (a < 0) a += mod;
  return a;
}
long long subt(long long a, long long b) { return mode(mode(a) - mode(b)); }
long long add(long long a, long long b) { return mode(mode(a) + mode(b)); }
long long mult(long long a, long long b) { return mode(mode(a) * mode(b)); }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> v(n), t(n);
  for (auto &to : v) cin >> to;
  priority_queue<pair<long long, long long> > K;
  long long ans = 0;
  long long timer = 0;
  for (; timer < n + k; timer++) {
    if (timer < n) {
      K.push(make_pair(v[timer], -timer));
    }
    if (timer >= k) {
      auto it = K.top();
      K.pop();
      ans += it.first * (timer - abs(it.second));
      t[abs(it.second)] = timer + 1;
    }
  }
  cout << ans << "\n";
  for (auto to : t) cout << to << ' ';
  return 0;
}
