最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#226(Div.2)ABearandRaspberry_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:57:04
文档

CodeforcesRound#226(Div.2)ABearandRaspberry_html/css

CodeforcesRound#226(Div.2)ABearandRaspberry_html/css_WEB-ITnose:题目链接:Bear and Raspberry Bear and Raspberry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
推荐度:
导读CodeforcesRound#226(Div.2)ABearandRaspberry_html/css_WEB-ITnose:题目链接:Bear and Raspberry Bear and Raspberry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

题目链接:Bear and Raspberry



Bear and Raspberry

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1?≤?i?≤?n) day, the price for one barrel of honey is going to is xikilos of raspberry.

Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1?≤?d?

The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.

Input

The first line contains two space-separated integers, n and c (2?≤?n?≤?100,?0?≤?c?≤?100), ? the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.

The second line contains n space-separated integers x1,?x2,?...,?xn (0?≤?xi?≤?100), the price of a honey barrel on day i.

Output

Print a single integer ? the answer to the problem.

Sample test(s)

input

5 15 10 7 3 20

output

input

6 2100 1 10 40 10 40

output

97

input

3 01 2 3

output

Note

In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.

In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.







解题思路:题目实质是 给一序列,找出后一个与前一个差距最大的值,并且结果要减去C。直接贪心加暴力,先扫一遍, 找出相邻元素中后一元素和前一元素差值最大的ans,如果ans < C ,则 ans = 0; 否则 ans = ans - C.






AC代码:

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x7fffffffint main(){ #ifdef sxk freopen("in.txt","r",stdin); #endif int n, c, a, b; while(scanf("%d%d",&n, &c)!=EOF) { int ans = 0; a = 0; for(int i=1; i<=n; i++){ cin>>b; if(a-b > ans) ans = a-b; a = b; } if(ans > c) ans -= c; else ans = 0; cout< 




声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

CodeforcesRound#226(Div.2)ABearandRaspberry_html/css

CodeforcesRound#226(Div.2)ABearandRaspberry_html/css_WEB-ITnose:题目链接:Bear and Raspberry Bear and Raspberry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
推荐度:
标签: () div.2 raspberry
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top