CF732B.Cormen — The Best Friend Of a Man

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 kk walks for any two consecutive days in order to feel good. For example, if k=5k=5 and yesterday Polycarp went for a walk with Cormen 22 times, today he has to go for a walk at least 33 times.

Polycarp analysed all his affairs over the next nn days and made a sequence of nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} , where aia_{i} is the number of times Polycarp will walk with the dog on the ii -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 nn days so that Cormen will feel good during all the nn days. You can assume that on the day before the first day and on the day after the nn -th day Polycarp will go for a walk with Cormen exactly kk times.

Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b1,b2,...,bnb_{1},b_{2},...,b_{n} ( bi>=aib_{i}>=a_{i} ), where bib_{i} means the total number of walks with the dog on the ii -th day.

输入格式

The first line contains two integers nn and kk ( 1<=n,k<=5001<=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 a1,a2,...,ana_{1},a_{2},...,a_{n} ( 0<=ai<=5000<=a_{i}<=500 ) — the number of walks with Cormen on the ii -th day which Polycarp has already planned.

输出格式

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

In the second line print nn integers b1,b2,...,bnb_{1},b_{2},...,b_{n} , where bib_{i} — the total number of walks on the ii -th day according to the found solutions ( ai<=bia_{i}<=b_{i} for all ii from 1 to nn ). If there are multiple solutions, print any of them.

输入输出样例

  • 输入#1

    3 5
    2 0 1
    

    输出#1

    4
    2 3 2
    
  • 输入#2

    3 1
    0 0 0
    

    输出#2

    1
    0 1 0
    
  • 输入#3

    4 6
    2 4 3 5
    

    输出#3

    0
    2 4 3 5
    
首页