A10581 | Cormen — The Best Friend Of a Man
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted