const
  maxn = 100;

var
  n, d, i, j, t, a, b, ans : integer;
  w : array[1..maxn] of integer;
begin
  reset(input, 'smbh.in');
  rewrite(output, 'smbh.out');
  read(n, d);
  assert((1 <= n) and (n <= maxn));
  assert((0 <= d) and (n <= 1000));
  for i := 1 to n do begin
    read(w[i]);
    assert((1 <= w[i]) and (w[i] <= 1000));
  end;
  for i := 1 to n do begin
    for j := i + 1 to n do begin
      if (w[i] < w[j]) then begin
        t := w[i];
        w[i] := w[j];
        w[j] := t;
      end;
    end;
  end;
  i := 2;
  a := d - 1;
  b := d + 1;
  ans := 0;
  while (i <= n) do begin
    if (a >= 0) then begin
      ans := ans + w[i] * (d - a);
      a := a - 1;
      i := i + 1;
    end;
    if (i <= n) then begin
      ans := ans + w[i] * (b - d);
      b := b + 1;
      i := i + 1;
    end;
  end;
  writeln(ans);
end.