#include <bits/stdc++.h>
using namespace std;
bool visited[800002];
int main() {
  long long int ans = 0;
  memset(visited, false, sizeof(visited));
  multimap<int, int, greater<int> > m;
  int n, a, b, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    m.insert(make_pair(a, i + 1));
  }
  multimap<int, int, greater<int> >::iterator it = m.begin();
  vector<pair<int, int> > v;
  for (int i = k + 1; i <= k + n && it != m.end(); i++) {
    if (visited[i] == true) continue;
    while (it->second > i && it != m.end() && visited[it->second] == false) {
      visited[it->second] = 1;
      v.push_back(make_pair(it->second, it->second));
      it++;
    }
    if (it == m.end()) break;
    if (visited[i] == true) continue;
    v.push_back(make_pair(it->second, i));
    ans += (long long int)(abs(i - it->second)) * it->first;
    visited[i] = 1;
    it++;
  }
  cout << ans << endl;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    printf("%d ", v[i].second);
  }
}
