time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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 = 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 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 integers b1, 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

【题解】



只要前一天和今天的次数和没有大于等于k,则增加当前天的次数,直至前一天和今天的次数和等于k。

勇敢贪吧。

#include <cstdio>

int a[600];
int n, k; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
a[0] = k; a[n + 1] = k;
int add = 0;
for (int i = 1; i <= n; i++)
{
int num = a[i - 1] + a[i];
if (num < k)
{
add += (k - num);
a[i] += (k - num);
}
}
printf("%d\n", add);
for (int i = 1; i <= n; i++)
printf("%d%c", a[i], i == n ? '\n' : ' ');
return 0;
}

【56.74%】【codeforces 732B】Cormen --- The Best Friend Of a Man的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【74.89%】【codeforces 551A】GukiZ and Contest

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【74.00%】【codeforces 747A】Display Size

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

  7. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  8. 【链表】【模拟】Codeforces 706E Working routine

    题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...

  9. 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions

    题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...

随机推荐

  1. amazeui学习笔记--css(常用组件15)--CSS动画Animation

    amazeui学习笔记--css(常用组件15)--CSS动画Animation 一.总结 1.css3动画封装:CSS3 动画封装,浏览器需支持 CSS3 动画. Class 描述 .am-anim ...

  2. amazeui学习笔记--css(HTML元素1)--按钮Button

    amazeui学习笔记--css(HTML元素1)--按钮Button 一.总结 1.button的基本使用:a.am-btn 在要应用按钮样式的元素上添加 .am-btn,b.颜色 再设置相应的颜色 ...

  3. iOS_05_变量的内存分析、Scanf函数

    一.变量的内存分析 1.字节和地址 * 为了更好地理解变量在内存中得存储细节,先来认识一下内存中得”字节“和”地址“. * 内存以字节为单位 * 不同类型占用的字节是不一样的,数据越大,所需的字节数九 ...

  4. IOS上架App Store商店步骤

    苹果官方在2015年05-06月开发者中心进行了改版,网上的APP Store上架大部分都不一样了,自己研究总结一下,一个最新的上架教程以备后用. 原文地址:http://www.16css.com/ ...

  5. 【Redis】redis的安装、配置执行及Jedisclient的开发使用

    定义: Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred ...

  6. 宝塔 ftp 不能连接 列出时出错

    摘抄自 https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=1903&page=1&extra=#pid6515 1.注意内网 ...

  7. 10.8 android输入系统_实战_使用GlobalKey一键启动程序

    11. 实战_使用GlobalKey一键启动程序参考文章:Android 两种注册(动态注册和静态注册).发送广播的区别http://www.jianshu.com/p/ea5e233d9f43 [A ...

  8. 17、网卡驱动程序-DM9000举例

    (参考:cs89x0.c可以参考) DM9000 芯片实现网络功能的基础,在接收数据时采用中断方式,即当有数据到来并在 DM9000 内部 CRC 校验通过后会产生一个接收中断: 网卡驱动程序框架: ...

  9. 10进制TO16进制

    string DecToHex(int Dec_Num){ int num; string str_num; num = Dec_Num; while(num / 16 != 0) { int a = ...

  10. 【BZOJ 1597】 [Usaco2008 Mar]土地购买

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把这n个土地按照x为第一关键字.y为第二关键字.都升序排. 然后考虑一个土地xi,yi 若有一个土地的x<=xi且y<= ...