CodeForces 732B Cormen — The Best Friend Of a Man
1 second
256 megabytes
standard input
standard 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 = 5and
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 integersb1, b2, ..., bn (bi ≥ ai),
where bi 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 a1, a2, ..., an (0 ≤ ai ≤ 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 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.
3 5
2 0 1
4
2 3 2
3 1
0 0 0
1
0 1 0
4 6
2 4 3 5
0
2 4 3 5
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h> using namespace std;
int n,k;
int a[505];
int b[505];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int ans=0;
for(int i=2;i<=n;i++)
{
if(a[i]+a[i-1]>=k) continue;
else
{
ans+=(k-a[i]-a[i-1]);
a[i]+=(k-a[i]-a[i-1]);
} }
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
if(i!=n)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
return 0; }
CodeForces 732B Cormen — The Best Friend Of a Man的更多相关文章
- CodeForces 732B Cormen — The Best Friend Of a Man (贪心)
题意:给定n和k表示,狗要在任意连续两天散步次数要至少为k,然后就是n个数,表示每天的时间,让你增加最少次数使得这个条件成立. 析:贪心,策略是从开始到最后暴力,每次和前面一个相比,如果相加不够k,那 ...
- 【56.74%】【codeforces 732B】Cormen --- The Best Friend Of a Man
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #377 (Div. 2)A,B,C,D【二分】
PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)
传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- OGG目的端的checkpoint table被drop的修复方法
OGG目的端的checkpoint table被drop的修复方法 參考自:OGG Replicat Failed Due To Check_point Table beingTruncated (文 ...
- 怎样在tsung中使用动态參数(二)
上一篇博客说过,在配置getOrderId请求时,能够用动态变量(order_id)解析和捕获服务端返回的json对象.这个变量能够作为接下来的订单确认请求(Confirm)的输入參数.看一下Conf ...
- atitit.loading的设计与实现控件选型attilax 总结
atitit.loading的设计与实现控件选型attilax 总结 1. Percentage Loader(推荐) 1 1.1. 起始百分比::调整 progress 1 2. CSS3 Loa ...
- Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道
Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Target Se ...
- ENGINE_API CXNoTouch
/************************************************************************/ //屏蔽消息面板 //优先级默认为 TP_BOTT ...
- Shape Control for .NET
Shape Control for .NET Yang Kok Wah, 23 Mar 2017 CPOL 4.83 (155 votes) Rate this: vote 1vote 2v ...
- [C++]红色波浪线是什么意思
相关资料:https://zhidao.baidu.com/question/242005953.html 问题现象:在写C++代码时,写的注释都是红色波浪线. 问题原因:波浪线表示 词语拼写错误 字 ...
- 基于jQuery实现文字倾斜显示代码
这是一款基于jQuery实现文字倾斜显示,这是一款基于jQuery实现的超酷动态文字显示效果.适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. ...
- jquery filter和not
jQuery filter() 方法 filter() 方法允许您规定一个标准.不匹配这个标准的元素会被从集合中删除,匹配的元素会被返回. 下面的例子返回带有类名 "intro" ...
- SpringBoot配置使用jsp页面技术
SpringBoot配置使用jsp页面技术 1.pom配置 package配置必须为war类型 添加依赖 <packaging>war</packaging> <depe ...