传送门:http://codeforces.com/problemset/problem/732/B

Cormen — The Best Friend Of a Man

time limit per test1 second

memory limit per test256 megabytes

Problem Description

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


解题心得:

  1. 题意很简单的,就是一个狗没两天走的总和必须大于等于k,他的主人已经有了一个行走的计划,问你为了狗他必须怎么改变自己的行走计划(只能在原有的计划上加行走路程),使他多走的路最少。
  2. 在比赛的时候老是读不懂题啊,慌得一批,其实就是一个贪心,每次在第二天上面加就行了。因为第二天可以作为第一天的第二天,也可以作为第三天的第二天。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int num[maxn];
int main()
{
int n,k;
while(cin>>n>>k)
{
for(int i=1;i<=n;i++)
scanf("%d",&num[i]);
int ans = 0;
for(int i=2;i<=n;i++)
{
int sum;
sum = num[i]+num[i-1];
if(sum < k)
{
num[i] += k-sum;
ans += k-sum;
}
}
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
printf("%d",num[i]);
if(i != n)
printf(" ");
else
printf("\n");
}
}
return 0;
}

CodeForce:732B-Cormen — The Best Friend Of a Man的更多相关文章

  1. CodeForces 732B Cormen — The Best Friend Of a Man (贪心)

    题意:给定n和k表示,狗要在任意连续两天散步次数要至少为k,然后就是n个数,表示每天的时间,让你增加最少次数使得这个条件成立. 析:贪心,策略是从开始到最后暴力,每次和前面一个相比,如果相加不够k,那 ...

  2. 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 megabyte ...

  3. CodeForce:16C-Monitor

    传送门:http://codeforces.com/problemset/problem/16/C Monitor time limit per test0.5 second memory limit ...

  4. Codeforces Round #377 (Div. 2)A,B,C,D【二分】

    PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...

  5. 各种OJ网站汇总

    acmicpc.info acmicpc.info http://acmicpc.info/archives/224 此网站聚合了各种ICPC相关信息. 国内Online Judge 用户体验极佳的v ...

  6. java web 开发三剑客 -------电子书

    Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...

  7. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  8. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  9. Codeforce 438D-The Child and Sequence 分类: Brush Mode 2014-10-06 20:20 102人阅读 评论(0) 收藏

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. D. Blocks 数学题

    Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent bo ...

  2. Zepto事件模块源码分析

    Zepto事件模块源码分析 一.保存事件数据的handlers 我们知道js原生api中要移除事件,需要传入绑定时的回调函数.而Zepto则可以不传入回调函数,直接移除对应类型的所有事件.原因就在于Z ...

  3. 下一代的前端构建工具:parcel打包react

    1. parcel很受欢迎,webpack太慢了,试试Parcel下一代的前端构建工具 2.Parcel很快,但缺少好多插件,没有base64,没有办法拆分打包文件.... 3.总结:适合小项目 4. ...

  4. BroadCast广播机制应用与实例

    如何编写广播接收器 第一步:需要继承BroadcastReceiver类,覆写其中的onReceive()方法. class MyBroadcastReceiver extends Broadcast ...

  5. cocos2dx贝塞尔曲线--使用PS辅助规划动作路径

    bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ...

  6. freebsd快速删除磁盘数据

    At the start, mark all system disks as empty. Repeat the following command for each hard drive: dd i ...

  7. Easyui validatebox后台服务端验证

    Easyui validatebox的验证提示十分好用,可是在实际项目的运用中,经常会遇到需要服务器验证后并返回验证结果信息,比如验证用户名.手机号.邮箱是否已存在.于是就想着怎么拓展Easyui的验 ...

  8. Image(支持 XML 序列化),注意C#中原生的Image类是无法进行Xml序列化的

    /// <summary> /// Image(支持 XML 序列化) /// </summary> [XmlRoot("XmlImage")] publi ...

  9. LR脚本示例之参数_变量介绍

    Action(){ char *url = "127.0.0.1:1080"; char arr_url[1024]; //将url变量的值复制给p_url1参数 lr_save_ ...

  10. Windows系统命令行下编译连接C/C++源代码方法

    Windows系统下编译连接源代码方法:cl -GX test.c-GX: 启动同步异常处理上面的命令会产生可执行程序:test.exe在命令行中直接输入:test.exe 就可运行该程序 Tips: ...