#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100000];
bool visited[100000] = {false};
void add_edge(vector<long long> adj[], long long a, long long b) {
  adj[a].push_back(b);
  adj[b].push_back(a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  pair<long long, long long> pa;
  long long n, k;
  cin >> n >> k;
  long long i, val;
  priority_queue<pair<long long, long long> > pq;
  vector<pair<long long, long long> > vp;
  for (i = 0; i <= k - 1; i++) {
    cin >> val;
    pa = make_pair(val, i + 1);
    pq.push(pa);
    vp.push_back(pa);
  }
  long long ans[400000];
  for (i = i; i <= n - 1; i++) {
    cin >> val;
    pa = make_pair(val, i + 1);
    pq.push(pa);
    vp.push_back(pa);
    pa = pq.top();
    ans[pa.second] = i + 1;
    pq.pop();
  }
  for (i = i; i <= n + k - 1; i++) {
    pa = pq.top();
    ans[pa.second] = i + 1;
    pq.pop();
  }
  long long ansi = 0;
  for (i = 1; i <= n; i++) {
    ansi += (ans[i] - i) * vp[i - 1].first;
  }
  cout << ansi << endl;
  for (i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
