#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9 + 7;
long long n, k, t[MAXN];
pair<long long, long long> c[MAXN];
long long re, x;
set<long long> s;
long long sum(long long a, long long b) { return (a + b) % MD; }
long long mu(long long a, long long b) { return (a * b) % MD; }
long long mn(long long a, long long b) { return (a - b + MD) % MD; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> c[i].first, c[i].second = i, re -= i * c[i].first, s.insert(i + k);
  sort(c + 1, c + n + 1);
  for (int i = n; i >= 1; --i) {
    set<long long>::iterator x = s.lower_bound((c[i].second));
    t[c[i].second] = *x;
    re += (*x) * (c[i].first);
    s.erase(x);
  }
  cout << re << endl;
  for (int i = 1; i <= n; ++i) cout << t[i] << ' ';
  return 0;
}
