# CodeForces 732B Cormen — The Best Friend Of a Man

B. Cormen — The Best Friend Of a Man

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 = 5and 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 a1, a2, ..., an, where ai 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 integersb1, b2, ..., bn (bi ≥ ai), where bi 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 a1, a2, ..., an (0 ≤ ai ≤ 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 b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i from 1 to n). If there are multiple solutions, print any of them.

Examples

input

```3 5
2 0 1```

output

```4
2 3 2```

input

```3 1
0 0 0```

output

```1
0 1 0```

input

```4 6
2 4 3 5```

output

```0
2 4 3 5```
```#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;
int n,k;
int a[505];
int b[505];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int ans=0;
for(int i=2;i<=n;i++)
{
if(a[i]+a[i-1]>=k) continue;
else
{
ans+=(k-a[i]-a[i-1]);
a[i]+=(k-a[i]-a[i-1]);
}

}
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
if(i!=n)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
return 0;

}```

0 条评论

• ### CodeForces 665B Shopping

B. Shopping time limit per test 1 second memory limit per test 256 megabyt...

• ### HOJ-2056 Bookshelf（线性动态规划）

L is a rather sluttish guy. He almost never clean up his surroundings or regulat...

• ### POJ-1953 World Cup Noise（线性动规）

World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissio...

• ### Duke@coursera 数据分析与统计推断unit5 inference for categorical variables

一、sampling variability & CLT for proportions

• ### 从MapX到MapXtreme2004[3]－搜索图元Feature

一、根据名称搜索图元 　　1、Mapxtreme的架构和Mapx有所变化，Mapx中，Layer包含Features，而Mapxtreme中则不是 　　2、...

• ### 除以3，乘以2（STL+排序）- Codeforces 997D

Polycarp likes to play with numbers. He takes some integer number x, writes it d...

• ### Duke@coursera 数据分析与统计推断unit6introduction to linear regression

properties (I) the magnitude (absolutevalue) of the correlation coefficient meas...

• ### R Programming week2 Functions and Scoping Rules

When R tries to bind a value to a symbol,it searches through a series of environ...

• ### TW洞见 | 敏捷回顾7步法

Paulo和TC一直在收集整理关于敏捷回顾的任何想法和活动。在这篇内容里面，他们分享了7步法来帮助你组织你的下一次回顾。 Agenda structure: 1...

• ### 统计学习导论 Chapter3--Linear Regression

Book: An Introduction to Statistical Learning with Applications in R http:...