#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
vector<long long> c(N, 0);
vector<long long> res(N, 0);
struct node {
  int r, c;
  int x, y;
  int dis;
  node(int i, int j, int x1, int y1, int d)
      : r(i), c(j), x(x1), y(y1), dis(d){};
};
bool isPrime(int n) {
  for (int i = 2; i <= int(sqrt(n)); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
int binarySearch(int *v, int begin, int end, int target) {
  if (begin <= end) {
    int mid = (begin + end) / 2;
    if (v[mid] == target) {
      end = mid - 1;
      return binarySearch(v, begin, end, target);
    } else if (v[mid] > target) {
      begin = mid + 1;
      return binarySearch(v, begin, end, target);
    } else if (v[mid] < target) {
      end = mid - 1;
      return binarySearch(v, begin, end, target);
    }
  }
  return end;
}
struct com {
  bool operator()(pair<int, int> p1, pair<int, int> p2) {
    if (p1.first == p2.first) {
      return p1.second > p2.second;
    }
    return p1.first < p2.first;
  }
};
int main(int, char **) {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, com> q;
  for (int i = 1; i <= k + 1 && i <= n; i++) {
    q.push(make_pair(c[i], i));
  }
  int index = k + 1;
  int out_index = k;
  long long sum = 0;
  while (!q.empty()) {
    auto t = q.top();
    out_index++;
    sum += t.first * (out_index - t.second);
    res[t.second] = out_index;
    q.pop();
    if (index < n) {
      index++;
      q.push(make_pair(c[index], index));
    }
  }
  cout << sum << endl;
  for (int i = 1; i <= n; i++) {
    cout << res[i] << " ";
  }
  return 0;
}
