#include <bits/stdc++.h>
using namespace std;
namespace std {
template <typename T>
void maxify(T &a, T b) {
  b > a && (a = b);
}
template <typename T>
void minify(T &a, T b) {
  b < a && (a = b);
}
}  // namespace std
struct IOManager {
  template <typename T>
  inline bool read(T &x) {
    char c;
    bool flag = false;
    x = 0;
    while (~c && !isdigit(c = getchar()) && c != '-')
      ;
    c == '-' && (flag = true, c = getchar());
    if (!~c) return false;
    while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
    return (flag && (x = -x), true);
  }
  inline bool read(char &c) {
    c = '\n';
    while (~c && !(isprint(c = getchar()) && c != ' '))
      ;
    return ~c;
  }
  inline long long read(char s[]) {
    char c;
    long long len = 0;
    while (~c && !(isprint(c = getchar()) && c != ' '))
      ;
    if (!~c) return 0;
    while (isprint(c) && c != ' ') s[len++] = c, c = getchar();
    return (s[len] = '\0', len);
  }
  template <typename T>
  inline IOManager operator>(T &x) {
    read(x);
    return *this;
  }
  template <typename T>
  inline void write(T x) {
    x < 0 && (putchar('-'), x = -x);
    x > 9 && (write(x / 10), true);
    putchar(x % 10 + '0');
  }
  inline void write(char c) { putchar(c); }
  inline void write(char s[]) {
    long long pos = 0;
    while (s[pos] != '\0') putchar(s[pos++]);
  }
  template <typename T>
  inline IOManager operator<(T x) {
    write(x);
    return *this;
  }
} io;
struct Flight {
  long long c, t;
  bool operator<(const Flight &f) const { return c > f.c; }
};
struct Solver {
 private:
  static const long long N = 700000;
  long long n, k, ans[N + 1], pre[N + 1], nxt[N + 1];
  bool vis[N + 1];
  Flight f[N + 1];
  void input() {
    io > n > k;
    for (long long i = 1; i <= n; ++i) io > f[i].c, f[i].t = i;
  }
  void init() {
    for (long long i = 1; i <= N; ++i) pre[i] = i - 1, nxt[i] = i + 1;
    sort(f + 1, f + n + 1);
  }
  long long get_nxt(long long t) {
    return vis[t] ? nxt[t] = get_nxt(nxt[t]) : t;
  }
  long long fill(long long t) {
    t = get_nxt(t);
    vis[t] = true, nxt[pre[t]] = nxt[t], pre[nxt[t]] = pre[t];
    return t;
  }
  void process() {
    long long tot = 0;
    for (long long i = 1; i <= n; ++i)
      ans[f[i].t] = fill(max(f[i].t, k + 1)),
      tot += (ans[f[i].t] - f[i].t) * f[i].c;
    io < tot < '\n';
    for (long long i = 1; i <= n; ++i) io < ans[i] < ' ';
    io < '\n';
  }

 public:
  void solve() { input(), init(), process(); }
} solver;
signed main() {
  solver.solve();
  return 0;
}
