#include <bits/stdc++.h>
using namespace std;
const int maxn = 300008;
int n, k;
long long sum = 0;
struct node {
  long long cost;
  int id;
  int t;
} a[maxn];
bool cmp1(node a, node b) {
  if (a.cost == b.cost) return a.id > b.id;
  return a.cost > b.cost;
}
bool cmp2(node a, node b) { return a.id < b.id; }
set<int> ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i].cost);
    a[i].id = i;
    ans.insert(k + i);
  }
  sort(a + 1, a + 1 + n, cmp1);
  for (int i = 1; i <= n; i++) {
    set<int>::iterator q = ans.lower_bound(a[i].id);
    a[i].t = *q;
    sum += (long long)(*q - a[i].id) * a[i].cost;
    ans.erase(*q);
  }
  sort(a + 1, a + 1 + n, cmp2);
  printf("%lld\n", sum);
  for (int i = 1; i <= n; i++) printf("%d ", a[i].t);
  puts("");
  return 0;
}
