#include <bits/stdc++.h>
using namespace std;
set<long long> ss;
long long n, k, base, ans;
pair<long long, pair<long long, long long> > c[300030];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = k + 1; i <= k + n; i++) ss.insert(i);
  for (int i = 0; i < n; i++) cin >> c[i].first, c[i].second.first = i + 1;
  sort(c, c + n,
       [](pair<long long, pair<long long, long long> > x,
          pair<long long, pair<long long, long long> > y) {
         return x.first > y.first;
       });
  for (int i = 0; i < n; i++) {
    c[i].second.second = *ss.lower_bound(c[i].second.first);
    ss.erase(ss.find(c[i].second.second));
    ans += c[i].first * abs(c[i].second.first - c[i].second.second);
  }
  sort(c, c + n,
       [](pair<long long, pair<long long, long long> > x,
          pair<long long, pair<long long, long long> > y) {
         return x.second.first < y.second.first;
       });
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << c[i].second.second << " ";
  return 0;
}
