#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int n, k, a[300009];
set<int> s;
int main() {
  cin >> n >> k;
  for (int i = k + 1; i <= k + n; i++) s.insert(i);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    v.push_back({x, i});
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    long long max1 = max(v[i].second, *(s.begin()));
    s.erase(max1);
    ans = ans + (max1 - v[i].second) * v[i].first;
    a[v[i].second] = max1;
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  return 0;
}
