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.
最近,波利卡普买了一只狗。这只狗的名字叫科门。现在波利卡普遇到了很多麻烦。例如,科门很喜欢散步。
根据经验,波利卡普发现:为了让科门感觉良好,任意连续两天内,狗至少需要散步 k 次。例如,若 k=5,而昨天波利卡普带科门散步了 2 次,则今天他至少还需再带科门散步 3 次。
波利卡普分析了接下来 n 天内自己的所有事务,并列出了一个长度为 n 的整数序列 a1,a2,…,an,其中 ai 表示在第 i 天,在完成所有事务(例如购物、倒垃圾等)的前提下,波利卡普计划带狗散步的次数。
请帮助波利卡普确定:在接下来的 n 天中,他最少需要额外增加多少次散步,才能保证科门在这 n 天内每天都感觉良好。你可以假设:在第 1 天之前的那一天,以及在第 n 天之后的那一天,波利卡普都会恰好带科门散步 k 次。
请编写一个程序,求出最少额外散步次数,以及对应的安排方案——即一个整数序列 b1,b2,…,bn(满足 bi≥ai),其中 bi 表示第 i 天实际带狗散步的总次数。
输入格式
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.
第一行包含两个整数 n 和 k(1≤n,k≤500)——分别表示天数,以及任意连续两天中与Cormen散步次数的最小值。
第二行包含 n 个整数 a1, a2, …, an(0≤ai≤500)——表示 Polycarp 已经计划好的第 i 天与 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 在接下来的 n 天内需要额外进行的最少散步次数,使得 Cormen 在所有天数内都感觉良好。
第二行输出 n 个整数 b1,b2,...,bn,其中 bi 表示根据所求方案第 i 天的总散步次数(对所有 i 从 1 到 n 均满足 ai≤bi)。若存在多种解,输出任意一种即可。
输入输出样例
输入#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测评打分。不知道怎么写?