日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bear and Raspberry

發(fā)布時間:2024/10/5 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bear and Raspberry 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Description
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 xi kilos 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?<?n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d?+?1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he’s got some raspberry left from selling the previous barrel) and immediately (on day d?+?1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.

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.

Examples
Input
5 1
5 10 7 3 20
Output
3
Input
6 2
100 1 10 40 10 40
Output
97
Input
3 0
1 2 3
Output
0
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語言版本一

#include <stdio.h> #include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {int n,m;scanf("%d%d",&n,&m);int i;int p[1000];for(i=0;i<n;i++){scanf("%d",&p[i]);}int min=p[0]-p[1]-m;for(i=1;i<n;i++){if(min<p[i-1]-p[i]-m){min=p[i-1]-p[i]-m;}}if(min<=0)printf("0\n");else printf("%d\n",min);return 0; }

C語言版本二

#include <stdio.h>int main() {int n,c,i,j,k,mi;int a[109];int b[109];while(scanf("%d %d",&n,&c)!=EOF){scanf("%d",&a[0]);for(i = 1; i<n; i++){scanf(" %d",&a[i]);b[i] = a[i-1] - a[i] - c;}mi = b[1];for(i = 2; i<n; i++){if(mi < b[i]){mi = b[i];}}if(mi <= 0)printf("0\n");elseprintf("%d\n",mi);}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Bear and Raspberry的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: www奇米影视com | 亚洲欧美日韩电影 | 国产黄色免费在线观看 | av成人免费| 成人精品一区二区三区四区 | www.天天干| 2023国产精品 | 色婷婷视频 | 久久人人干| 免费视频网站www | 日韩影院在线 | va欧美 | 秋霞成人午夜伦在线观看 | 黑人操亚洲女 | 成人做受视频试看60秒 | 国产一级在线播放 | 亚洲成av人片在www色猫咪 | 欧美疯狂做受xxxxx高潮 | 亚洲欧美日韩在线一区 | 在线播放一区 | 亚洲天堂91 | 老熟妇午夜毛片一区二区三区 | 色九月婷婷 | 一级黄色片免费 | 亚洲性免费 | 性高潮久久久久久久 | 成人爽爽视频 | 美女av片| 麻豆回家视频区一区二 | 久久永久免费 | 久艹av | 日韩av在线直播 | 亚洲欧美影院 | 无码人妻丰满熟妇精品区 | 日韩一区二区三区四区五区六区 | 亚洲一区二区三区四区不卡 | 久久大片 | 伊人久久久久噜噜噜亚洲熟女综合 | 国产无遮挡a片又黄又爽 | 日韩成人在线观看 | 被灌满精子的波多野结衣 | 伊伊综合网 | 97视频成人 | 国产尤物网站 | 国产九一精品 | 日韩成年视频 | 欧美激情婷婷 | 久色免费视频 | 国产永久免费 | 日日爱886 | 亲子乱aⅴ一区二区三区 | 黄色网入口 | 日韩精品二区在线观看 | 噼里啪啦免费高清看 | 国产午夜精品无码一区二区 | 日本一区二区三区视频在线观看 | 亚洲一级av无码毛片精品 | 污黄网站在线观看 | 伊人久久免费 | aa级黄色片 | xxxx日本少妇 | 午夜小福利 | 国产成人无码精品久久久电影 | 亚洲一区二区三区人妻 | 久久四色 | 国产精品一二三四区 | 申鹤乳液狂飙 | 亚洲乱码电影 | 国产传媒在线观看 | 诱人的乳峰奶水hd | 免费黄色三级 | 国产精品熟女一区二区不卡 | 黑人干亚洲女 | 三级欧美韩日大片在线看 | 操女人网 | 99热这里是精品 | 国产网址在线观看 | 美女张开腿让男人桶爽 | 日韩少妇内射免费播放18禁裸乳 | 天堂成人在线观看 | 亚洲网站免费观看 | 人物动物互动39集免费观看 | 精品少妇人妻av一区二区三区 | 操操操干干干 | 精品久久伊人 | 成人黄色一级视频 | 国产高清一二三区 | 久久深夜视频 | 国产精品极品白嫩在线 | 操她视频网站 | 久久精品高清 | 日日夜夜撸撸 | a级小视频 | 狠狠入| 快播91| freesex性hd公交车上 | 国产偷人妻精品一区 | 鲁大师私人影院在线观看 | 国产一区二区三区免费观看 |