#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::lower_bound;
using std::make_pair;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::upper_bound;
using std::vector;
struct node {
  int id;
  long long cost;
  bool operator<(const node b) const { return cost < b.cost; }
};
node a[300001];
int seq[300001];
int main(int argc, char** argv) {
  if (argc == 2 && strcmp(argv[1], "-debug") == 0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    a[i].id = i;
    scanf("%lld", &a[i].cost);
  }
  int j = k;
  long long ans = 0;
  priority_queue<node> q;
  for (int i = 1; i <= k; i++) q.push(a[i]);
  for (int i = 1; i <= n; i++) {
    ++j;
    if (j <= n) q.push(a[j]);
    node t = q.top();
    q.pop();
    ans += t.cost * (i + k - t.id);
    seq[t.id] = j;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) printf("%d ", seq[i]);
  return 0;
}
