Codeforces Round 377 (Div. 2)
B
Cormen — The Best Friend Of a Man
Codeforces
1000
原题
← AC →
翻译中…

Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.

翻译中…

Empirically Polycarp learned that the dog needs at least $*k*$ walks for any two consecutive days in order to feel good. For example, if $*k* = 5$ and yesterday Polycarp went for a walk with Cormen $2$ times, today he has to go for a walk at least $3$ times.

翻译中…

Polycarp analysed all his affairs over the next $*n*$ days and made a sequence of $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$, where $*a*_{*i*}$ is the number of times Polycarp will walk with the dog on the $*i*$-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).

翻译中…

Help Polycarp determine the minimum number of walks he needs to do additionaly in the next $*n*$ days so that Cormen will feel good during all the $*n*$ days. You can assume that on the day before the first day and on the day after the $*n*$-th day Polycarp will go for a walk with Cormen exactly $*k*$ times.

翻译中…

Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$ ($*b*_{*i*} ≥ *a*_{*i*}$), where $*b*_{*i*}$ means the total number of walks with the dog on the $*i*$-th day.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ ($1 ≤ *n*, *k* ≤ 500$) — the number of days and the minimum number of walks with Cormen for any two consecutive days.

翻译中…

The second line contains integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($0 ≤ *a*_{*i*} ≤ 500$) — the number of walks with Cormen on the $*i*$-th day which Polycarp has already planned.

翻译中…

Output

翻译中…

In the first line print the smallest number of additional walks that Polycarp should do during the next $*n*$ days so that Cormen will feel good during all days.

翻译中…

In the second line print $*n*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$, where $*b*_{*i*}$ — the total number of walks on the $*i*$-th day according to the found solutions ($*a*_{*i*} ≤ *b*_{*i*}$ for all $*i*$ from 1 to $*n*$). If there are multiple solutions, print any of them.

翻译中…

样例

Input #1
3 5
2 0 1
Output #1
4
2 3 2
InputCopy OutputCopy
Input #2
3 1
0 0 0
Output #2
1
0 1 0
InputCopy OutputCopy
Input #3
4 6
2 4 3 5
Output #3
0
2 4 3 5
InputCopy OutputCopy
题目信息
题号
732B
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。