• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #226 Div2 A

   
     
 

Sponsored by             
In English             По-русски        
HaibaraAi                 |                  Logout                        
 
 
 
 
 
  • Home
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Help
                                     
        
 
 
Codeforces Round #226 (Div. 2)
Finished
Practice
Add to favourites         
 
 
→ Practice            
 
        You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.    
    
 
 
→ Submit?            
 
                                   
Language:                 
Choose file:                 
                                Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it will pass system tests.                            
                    
 
 
→ Last submissions            
 
SubmissionTimeVerdict
5789260 01/24/2014 07:58PM Accepted
 
 
→ Problem tags            
 
 
 
 
 
    brute force     
 
 
 
 
    greedy     
 
 
 
 
    implementation     
No tag edit access    
              
              
                
                
  •  
     
     
  • Problems
  • Submit
  • My submissions
  • Status
  • Hacks
  • Room
  • Standings
  • Custom test
A. 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 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.

Sample test(s)
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.

            

Codeforces (c) Copyright 2010-2014 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: 01/26/2014 10:35PM (p1).
 
 
 
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff 
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1000025
14 #define pi acos(-1.0)
15 int n, m;
16 int a[maxn];
17 int main(){
18     scanf("%d%d", &n, &m);
19     for (int i = 0; i < n; i++){
20         scanf("%d", &a[i]);
21     }
22     int x = 0;
23     for (int i = 1; i < n; i++){
24         x = max(x,a[i - 1] - a[i]);
25     }
26     printf("%d\n", max(0,x - m));
27     return 0;
28 }
View Code
posted @ 2014-01-27 02:36  HaibaraAi  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3