#include <bits/stdc++.h>
using namespace std;
long long n, m, *trees, *peoples, *ostart, *ofinish, *lens;
long long START = -2 * 1000000000;
long long FINISH = 2 * 1000000000;
void qs2(long long *s_arr, long long first, long long last) {
  if (first < last) {
    long long left = first, right = last, middle = s_arr[(left + right) / 2];
    do {
      while (s_arr[left] < middle) left++;
      while (s_arr[right] > middle) right--;
      if (left <= right) {
        long long tmp = s_arr[left];
        s_arr[left] = s_arr[right];
        s_arr[right] = tmp;
        long long tmp1 = ostart[left];
        ostart[left] = ostart[right];
        ostart[right] = tmp1;
        long long tmp2 = ofinish[left];
        ofinish[left] = ofinish[right];
        ofinish[right] = tmp2;
        left++;
        right--;
      }
    } while (left <= right);
    qs2(s_arr, first, right);
    qs2(s_arr, left, last);
  }
}
void qs2(long long *s_arr, long long size) { qs2(s_arr, 0, size - 1); }
void qs(long long *s_arr, long long first, long long last) {
  if (first < last) {
    long long left = first, right = last, middle = s_arr[(left + right) / 2];
    do {
      while (s_arr[left] < middle) left++;
      while (s_arr[right] > middle) right--;
      if (left <= right) {
        long long tmp = s_arr[left];
        s_arr[left] = s_arr[right];
        s_arr[right] = tmp;
        left++;
        right--;
      }
    } while (left <= right);
    qs(s_arr, first, right);
    qs(s_arr, left, last);
  }
}
void qs(long long *s_arr, long long size) { qs(s_arr, 0, size - 1); }
int max(int a1, int a2) {
  if (a1 > a2)
    return a1;
  else
    return a2;
}
int min(int a1, int a2) {
  if (a1 < a2)
    return a1;
  else
    return a2;
}
long long decision() {
  long long res = 0;
  int j = 1;
  int k = 0, i1 = 0, i2 = 0, j1, j2;
  ostart = new long long[2 * n];
  ofinish = new long long[2 * n];
  lens = new long long[2 * n];
  qs(trees, n);
  for (int i = 0; i < n; i++) {
    ostart[2 * i] = trees[i] - 1;
    ostart[2 * i + 1] = trees[i] + 1;
    if (i == 0) {
      ofinish[2 * i] = START - 1;
      if (i == n - 1)
        ofinish[2 * i + 1] = FINISH + 1;
      else
        ofinish[2 * i + 1] = (trees[i] + trees[i + 1]) / 2 + 1;
    } else if (i == n - 1) {
      if (i == 0)
        ofinish[2 * i] = START - 1;
      else
        ofinish[2 * i] = (trees[i - 1] + trees[i]) / 2;
      ofinish[2 * i + 1] = FINISH + 1;
    } else {
      ofinish[2 * i] = (trees[i - 1] + trees[i]) / 2;
      ofinish[2 * i + 1] = (trees[i] + trees[i + 1]) / 2 + 1;
    }
    lens[2 * i] = ostart[2 * i] - ofinish[2 * i];
    lens[2 * i + 1] = ofinish[2 * i + 1] - ostart[2 * i + 1];
  }
  qs2(lens, 2 * n);
  long long tm = m, tindex = 0;
  long long lindex = 0;
  long long kCurrent = 0;
  while (tm > 0) {
    while (lens[lindex] - kCurrent <= 0) lindex++;
    int c = 2 * n - lindex;
    tm -= c * (lens[lindex] - kCurrent);
    int ki = 0;
    for (; tindex < m && ki < c * (lens[lindex] - kCurrent); tindex++) {
      int lind = lindex + ki % c;
      int sh = kCurrent + ki / c;
      if (ostart[lind] > ofinish[lind]) {
        peoples[tindex] = ostart[lind] - sh;
        res += ostart[lind] + 1 - peoples[tindex];
      } else {
        peoples[tindex] = ostart[lind] + sh;
        res += peoples[tindex] - (ostart[lind] - 1);
      }
      ki++;
    }
    kCurrent = lens[lindex];
  }
  return res;
}
int main() {
  cin >> n >> m;
  trees = new long long[n + 1];
  peoples = new long long[m + 1];
  for (int i = 0; i < n; i++) {
    cin >> trees[i];
  }
  cout << decision() << endl;
  for (int i = 0; i < m; i++) cout << peoples[i] << " ";
  return 0;
}
