CodeForces 732B Cormen — The Best Friend Of a Man
来源:互联网 发布:战意首测激活码淘宝 编辑:程序博客网 时间:2024/06/05 10:59
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 52 0 1
42 3 2
3 10 0 0
10 1 0
4 62 4 3 5
02 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 (水题)
- 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 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
- 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
- CodeForces 732B Cormen — The Best Friend Of a Man(带着宠物轧马路)
- Cormen — The Best Friend Of a Man (贪心)
- codeforce#377B. Cormen — The Best Friend Of a Man
- Cocos2d-lua示例(一)排行榜之ScrollView
- 利用IDEA创建Web Service服务端和客户端
- Hadoop安装教程_伪分布式配置_CentOS7.x/Hadoop2.7.3
- 制作gif小软件的使用
- 目标检测之训练opencv自带的分类器(opencv_haartraining 或 opencv_traincascade)
- CodeForces 732B Cormen — The Best Friend Of a Man
- Android SDK上手指南:虚拟与物理设备
- session原理及实现共享 (精简)
- Sender address<*@*>domain does not exist 的解决方法
- 事件
- linux 常用基本命令之三十二 fdisk (mkfs.ext*格式化分区)
- MySQL的DISTINCT
- 使用QEmu调试Linux内核 “No symbol table is loaded.”
- 圆圆照片