#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int t = 0, ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (k > (arr[i] + arr[i + 1])) {
      ans += k - arr[i] - arr[i + 1];
      arr[i + 1] = k - arr[i];
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
}
