传送门: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. html select change事件触发

    做小组内使用的一个简单工具,其中要实现的一个小功能是当某个下拉菜单的选择值改变时触发另一表单元素的属性变化.自然的想到使用select表单元素的onchange事件. 下拉菜单部分的代码如下: < ...

  2. Swagger 2.0 集成配置

    传统的API文档编写存在以下几个痛点: 对API文档进行更新的时候,需要通知前端开发人员,导致文档更新交流不及时: API接口返回信息不明确 大公司中肯定会有专门文档服务器对接口文档进行更新. 缺乏在 ...

  3. jQuery的一些备忘

    操作元素的样式 主要包括以下几种方式: $("#msg").css("background"); //返回元素的背景颜色 $("#msg") ...

  4. 好吧,不说闲言碎语,不抱怨,好好工作,好好学习,多总结。记录一下昨天做vuejs的心得

    1.做了两个bat文件,一个是直接定位到vuejs项目并且运行,另一个就是打包 run.bat d:cd wwwcd vuecd dtbpmcnpm run devpause build.bat cd ...

  5. RSA_new()初始化和RSA_free()释放RSA结构体后依然会有内存泄漏(转)

    在使用OpenSSL的RSA加解密的时候,发现RSA_new()初始化和RSA_free()释放RSA结构体后依然会有内存泄漏.网上Baidu.Google之,发现这个相关信息很少(至少中文搜索结果是 ...

  6. 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:4.技术简介之Spring

    欢迎阅读我的开源项目<迷你微信>服务器与<迷你微信>客户端 Spring是一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One ...

  7. ./theHarvester.py -d baidu.com -l 100 -b google

    ./theHarvester.py -d baidu.com  -l 100 -b google

  8. python爬虫之路——初识函数与控制语句

    介绍python函数的定义与使用方法,介绍Python的常用控制语句:判断和循环 函数: 格式 def   函数名(参数1,参数2): return ‘结果’ 判断语句:就是多选一 二选一: if c ...

  9. 感觉单链表是实现BCL ICollection 的最佳方式,所有操作都能以最小的时间复杂度完成

    public interface ICollection<T> : IEnumerable<T>, IEnumerable {     int Count { get; }// ...

  10. bzoj3209:3209: 花神的数论题

    觉得还是数位dp的那种解题形式但是没有认真的想,一下子就看题解.其实还是设置状态转移.一定要多思考啊f[i][j]=f[i-1][j]+g[i-1][j] g[i][j]=f[i-1][j-1]+g[ ...