#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 5;
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
long long power(long long base, long long exp, long long mod = 1000000007) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
priority_queue<pair<long long, long long> > q;
long long a[N];
vector<pair<long long, long long> > v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, ct = 0, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i += 1) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i += 1) {
    q.push(make_pair(a[i], i));
  }
  for (int i = k + 1; i <= k + n; i += 1) {
    if (ct >= n) break;
    if (i <= n) q.push(make_pair(a[i], i));
    ans += (i - q.top().second) * q.top().first;
    ct++;
    v.push_back(make_pair(q.top().second, i));
    q.pop();
    if (ct >= n) break;
  }
  cout << ans << "\n";
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)v.size(); i += 1) {
    cout << v[i].second << " ";
  }
}
