#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const int mod = 1e9 + 7;
int a[maxn], used[maxn];
priority_queue<pair<int, int> > pq;
set<int> s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = k + 1; i <= k + n; i++) s.insert(i);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pq.push({a[i], i});
  }
  long long ans = 0;
  while (!pq.empty()) {
    pair<int, int> now = pq.top();
    pq.pop();
    int d = *(s.lower_bound(now.second));
    used[now.second] = d;
    ans += (d - now.second) * 1ll * a[now.second];
    s.erase(d);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << used[i] << ' ';
}
