Codeforce 264 B Caisa and Pylons(模拟)
题意 Caisa走台阶 有n个台阶 第i个台阶的高度为h[i] 从第i个台阶包括地面到下一个台阶得到的能量为h[i]-h[i+1] 能量不足以跳到下一个台阶就要补充能量 求Caisa跳完所有台阶最少要补充多少能量
水题 直接模拟
1 | #include<cstdio> |
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are(n + 1)pylons numbered from0tonin this game. The pylon with number0has zero height, the pylon with numberi(i > 0)has heighth**i. The goal of the game is to reachn-th pylon, and the only move the player can do is to jump from the current pylon (let’s denote its number ask) to the next one (its number will bek + 1). When the player have made such a move, its energy increases byh**k - h**k + 1(if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at0pylon and has0energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn’t want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Input
The first line contains integern(1 ≤ n ≤ 105). The next line containsnintegersh1,h2, …,h**n(1 ≤ h**i ≤ 105)representing the heights of the pylons.
Output
Print a single number representing the minimum number of dollars paid by Caisa.
Sample test(s)
input 5 3 4 3 2 4
output 4
input 3 4 4 4
output 4
Note
In the first sample he can pay4dollars and increase the height of pylon with number0by4units. Then he can safely pass to the last pylon.