Saleh127

Untitled

May 10th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int a[100000],c,d,e=0,f=0,i,j,k,l;
  6. cin>>c>>d;
  7. for(i=0; i<c; i++)
  8. {
  9. cin>>a[i];
  10. }
  11. for(i=1; i<c; i++)
  12. {
  13. l=d-a[i]-a[i-1];
  14. f=max(0,l);
  15. e+=f;
  16. a[i]+=f;
  17. }
  18. printf("%d\n",e);
  19. for(j=0; j<c; j++)
  20. {
  21. printf("%d ",a[j]);
  22. }
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment