CF732B.Cormen — The Best Friend Of a Man

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

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 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 _a_1, _a_2, ..., a__n, where a__i 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 _b_1, _b_2, ..., b__n (b__i ≥ a__i), where b__i means the total number of walks with the dog on the i-th day.

最近,波利卡普买了一只狗。这只狗的名字叫科门。现在波利卡普遇到了很多麻烦。例如,科门很喜欢散步。

根据经验,波利卡普发现:为了让科门感觉良好,任意连续两天内,狗至少需要散步 kk 次。例如,若 k=5k = 5,而昨天波利卡普带科门散步了 22 次,则今天他至少还需再带科门散步 33 次。

波利卡普分析了接下来 nn 天内自己的所有事务,并列出了一个长度为 nn 的整数序列 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n,其中 aia_i 表示在第 ii 天,在完成所有事务(例如购物、倒垃圾等)的前提下,波利卡普计划带狗散步的次数。

请帮助波利卡普确定:在接下来的 nn 天中,他最少需要额外增加多少次散步,才能保证科门在这 nn 天内每天都感觉良好。你可以假设:在第 11 天之前的那一天,以及在第 nn 天之后的那一天,波利卡普都会恰好带科门散步 kk 次。

请编写一个程序,求出最少额外散步次数,以及对应的安排方案——即一个整数序列 b1, b2, …, bnb_1,\,b_2,\,\dots,\,b_n(满足 bi≥aib_i \ge a_i),其中 bib_i 表示第 ii 天实际带狗散步的总次数。

输入格式

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 _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.

第一行包含两个整数 nn 和 kk(1≤n,k≤5001 \leq n, k \leq 500)——分别表示天数,以及任意连续两天中与Cormen散步次数的最小值。

第二行包含 nn 个整数 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n(0≤ai≤5000 \leq a_i \leq 500)——表示 Polycarp 已经计划好的第 ii 天与 Cormen 散步的次数。

输出格式

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 _b_1, _b_2, ..., b__n, where b__i — the total number of walks on the i-th day according to the found solutions (a__i ≤ b__i for all i from 1 to n). If there are multiple solutions, print any of them.

第一行输出 Polycarp 在接下来的 nn 天内需要额外进行的最少散步次数,使得 Cormen 在所有天数内都感觉良好。

第二行输出 nn 个整数 b1, b2, ..., bnb_1,\,b_2,\,...,\,b_n,其中 bib_i 表示根据所求方案第 ii 天的总散步次数(对所有 ii 从 11 到 nn 均满足 ai ≤ bia_i\,\leq\,b_i)。若存在多种解,输出任意一种即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页