#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 14;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i].first;
    v[i].second = i + 1;
  }
  set<long long> seen;
  for (long long i = k; i <= n + k; ++i) seen.insert(i);
  vector<long long> res(n);
  sort(v.rbegin(), v.rend());
  long long fi = 0LL;
  for (long long i = 0; i < n; ++i) {
    long long y = max(k + 1, v[i].second);
    auto j = seen.lower_bound(y);
    res[v[i].second - 1] = *j;
    fi += (*j - v[i].second) * (v[i].first);
    seen.erase(*j);
  }
  cout << fi << "\n";
  for (long long x : res) cout << x << " ";
  cout << "\n";
  return 0;
}
