#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int main() {
  int n, k;
  cin >> n >> k;
  int a[N];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  set<int> s;
  map<int, vector<int> > M;
  for (int i = 1; i <= k; i++) {
    M[a[i]].push_back(i);
    s.insert(a[i]);
  }
  long long ans = 0;
  int idx[N];
  for (int i = k + 1; i <= k + n; i++) {
    if (i <= n) M[a[i]].push_back(i);
    if (i <= n) s.insert(a[i]);
    set<int>::iterator it = s.end();
    it--;
    idx[M[*it].back()] = i;
    ans += (long long)(i - M[*it].back()) * (long long)(*it);
    M[*it].pop_back();
    if (M[*it].size() == 0) s.erase(*it);
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) {
    printf("%d ", idx[i]);
  }
  return 0;
}
