#include <bits/stdc++.h>
using namespace std;
int A[1000], B[1000];
int main() {
  int n, k, sum = 0, summ = 0;
  cin >> n >> k;
  for (long long int i = (long long int)1; i <= (long long int)n; i++) {
    cin >> A[i];
    sum += A[i];
  }
  B[1] = A[1];
  summ = B[1];
  for (long long int i = (long long int)2; i <= (long long int)n; i++) {
    B[i] = max(A[i], k - B[i - 1]);
    summ += B[i];
  }
  cout << summ - sum << "\n";
  for (long long int i = (long long int)1; i <= (long long int)n; i++)
    cout << B[i] << " ";
}
