#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 7;
const int INF = 0x7fffffff;
long long n, k;
struct Point {
  long long c;
  long long t;
} p[maxn];
bool cmp(Point a, Point b) { return a.c > b.c; }
int vis[12000005];
int vec[maxn];
int main() {
  while (cin >> n >> k) {
    for (int i = 0; i < n; i++) {
      scanf("%I64d", &p[i].c);
      p[i].t = i + 1;
    }
    memset(vis, 0, sizeof(vis));
    sort(p, p + n, cmp);
    long long ans = 0;
    k++;
    for (int i = 0; i < n; i++) {
      for (long long j = max(k, p[i].t);; j++) {
        while (vis[k] && j == k) {
          k++;
          j++;
        }
        if (!vis[j]) {
          vis[j] = 1;
          ans += (j - p[i].t) * p[i].c;
          vec[p[i].t] = j;
          break;
        }
      }
    }
    cout << ans << endl;
    cout << vec[1];
    for (int i = 2; i <= n; i++) cout << ' ' << vec[i];
    cout << endl;
  }
  return 0;
}
