#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int ar[MAXN];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  long long ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < n - 1; i++) {
    if (ar[i] + ar[i + 1] < k) {
      ans += k - ar[i] - ar[i + 1];
      ar[i + 1] += k - ar[i] - ar[i + 1];
    }
  }
  ar[n - 1] += ar[n];
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << ar[i] << ' ';
}
