#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int c[300001], g[300001];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  priority_queue<pair<int, int> > pq;
  k--;
  long long cost = 0;
  for (int i = 0; i < n || (!pq.empty()); i++) {
    if (i < n) pq.push(pair<int, int>(c[i], i));
    if (i > k) {
      pair<int, int> re = pq.top();
      pq.pop();
      cost += 1LL * re.first * (i - re.second);
      g[re.second] = i + 1;
    }
  }
  cout << cost << endl;
  for (int i = 0; i < n; i++) cout << g[i] << " ";
  cout << endl;
  return 0;
}
