CodeForces-732B-Cormen — The Best Friend Of a Man(简单模拟)
来源:互联网 发布:开源大数据可视化工具 编辑:程序博客网 时间:2024/05/23 21:45
B. Cormen — The Best Friend Of a Man
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
题意:首行给出N和K,表示有N天,每两天的遛狗时间之和要大于等于K,如果时间不够,就在后一天补上,接着一行输入N个数字代表每天的遛狗时间,输出补充的时间和补充后每天的遛狗时间
代码
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;const int maxn=505;int main(){ int N,K; scanf("%d%d",&N,&K); int num[maxn]; int result=0; scanf("%d",&num[0]); for(int i=1;i<N;i++) { scanf("%d",&num[i]); if(num[i]+num[i-1]<K) { result+=K-num[i]-num[i-1]; num[i]=K-num[i-1]; } } printf("%d\n",result); for(int i=0;i<N;i++) printf("%d ",num[i]); return 0;}
- CodeForces-732B-Cormen — The Best Friend Of a Man(简单模拟)
- codeforces 732B - Cormen --- The Best Friend Of a Man
- codeforces 732B Cormen — The Best Friend Of a Man (水题)
- CodeForces 732 B.Cormen — The Best Friend Of a Man(贪心)
- CodeForces 732B Cormen — The Best Friend Of a Man
- Codeforces 732B Cormen — The Best Friend Of a Man【贪心】
- Codeforces 732B-Cormen—The Best Friend Of a Man
- CodeForces 732B 之 Cormen — The Best Friend Of a Man
- CodeForces 732B Cormen — The Best Friend Of a Man
- codeforces 732B Cormen — The Best Friend Of a Man
- CodeForces 732B Cormen — The Best Friend Of a Man
- CodeForces 732B Cormen — The Best Friend Of a Man(带着宠物轧马路)
- B. Cormen — The Best Friend Of a Man
- 【56.74%】【codeforces 732B】Cormen --- The Best Friend Of a Man
- 【codeforces 723 B Cormen — The Best Friend Of a Man】
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man
- Cormen — The Best Friend Of a Man (贪心)
- codeforce#377B. Cormen — The Best Friend Of a Man
- string中c_str()、data()、copy(p,n)函数的用法
- spring AOP中对拦截器调用的实现
- SWF获取cookie与js函数返回值
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android studio必做的几个优化配置。
- CodeForces-732B-Cormen — The Best Friend Of a Man(简单模拟)
- Linux PWM framework_简介和API描述
- “无法查找或打开PDB文件”解决办法
- 数据结构实验之数组三:快速转置
- 【android】第三方集成之——极光推送
- PMP学习笔记之第13章 项目干系人管理 ——13.2规划干系人管理
- python3 模块构建与发布
- 23 leetcode - Generate Parentheses
- Android Retrofit框架解析