#include <bits/stdc++.h>
using namespace std;
int n, i, A[500], ans[500], m, k;
int main() {
  ios_base::sync_with_stdio(0);
  m = 0;
  cin >> n >> k;
  m = 0;
  for (i = 0; i < n; i++) cin >> A[i];
  memset(ans, 0, n);
  ans[0] = A[0];
  for (i = 1; i < n; i++) {
    if (A[i] + ans[i - 1] >= k) {
      ans[i] = A[i];
      continue;
    }
    ans[i] = ans[i] + (k - ans[i - 1]);
    m = m + ans[i] - A[i];
  }
  cout << m << '\n';
  for (i = 0; i < n; i++) cout << ans[i] << " ";
}
