B. Cormen — The Best Friend Of a Man1000 / 贪心

Posted 幽殇默

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Cormen — The Best Friend Of a Man1000 / 贪心相关的知识,希望对你有一定的参考价值。


https://codeforces.com/problemset/problem/732/B
只要判断后面即可,不过感觉题目有点不清楚就是n==1的情况该咋办,答案是直接输出原来的即可。

#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main(void)
{
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	int sum=0;
	for(int i=1;i<n;i++)
	{
		int temp=a[i];
		if(a[i]+a[i-1]<k) a[i]=k-a[i-1],sum+=a[i]-temp;
	}
	cout<<sum<<endl;
	for(int i=0;i<n;i++) cout<<a[i]<<" ";
	return 0;
}

以上是关于B. Cormen — The Best Friend Of a Man1000 / 贪心的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 732B Cormen --- The Best Friend Of a Man

Codeforces Round #524 (Div. 2) B. Margarite and the best present

ACM-ICPC 2015 Shenyang Preliminary Contest B. Best Solver

The Best Technique To Approach The Best Packers And Movers In Bangalore

Lesson 8 The best and the worst

The 10 Best Choices On The Market Review 2018