Codeforce 264 B Caisa and Pylons(模拟)



题意   Caisa走台阶  有n个台阶  第i个台阶的高度为h[i]  从第i个台阶包括地面到下一个台阶得到的能量为h[i]-h[i+1]  能量不足以跳到下一个台阶就要补充能量  求Caisa跳完所有台阶最少要补充多少能量

水题   直接模拟

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 100005;
int h[N];
int main()
{
    int n, e, ans;
    scanf("%d",&n);
    for (int i = 1; i <= n; ++i)
        scanf ("%d", &h[i]);
    ans = 0;
    for (int i = e = 0; i < n; ++i)
    {
        if (h[i] + e < h[i + 1])
        {
            int t = (h[i + 1] - e - h[i]);
            h[i] += t;
            ans += t;
        }
        e += (h[i] - h[i + 1]);
    }
    printf ("%d\n", ans);
    return 0;
}

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 from 0 to n in
this game. The pylon with number 0 has zero height, the pylon with number i (i?>?0) has
height hi.
The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon
(let‘s denote its number as k) to the next one (its number will be k?+?1).
When the player have made such a move, its energy increases by hk?-?hk?+?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 at 0 pylon and has 0 energy.
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 integer n (1?≤?n?≤?105).
The next line contains n integers h1h2,?..., hn (1??≤??hi??≤??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 pay 4 dollars and increase the
height of pylon with number 0 by 4 units.
Then he can safely pass to the last pylon.

时间: 2024-11-04 10:20:53

Codeforce 264 B Caisa and Pylons(模拟)的相关文章

Codeforce 264 A Caisa and Sugar(简单)

Caisa去商店买Sugar  商店找零的最低单位为元  低于1元的部分每分找一个糖果   商店有n种Suger Caisa有s元钱  她只买一种Sugar  输入n s 再输入n行  每行两个数a b  表示第i种Sugar的单价为a元b分   求Sugar最多能被找多少糖果 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int n, s

codeforces B#264. Caisa and Pylons

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 from 0 to n in this game. The pylon with number 0 has zero height, the pylon with numberi

CodeForce 7 B - Memory Manager(模拟)

题目大意:给你一段内存,要你进行如下的三个操作. 1.分配内存  alloc   X ,分配连续一段长度为X的内存. 如果内存不够应该输出NULL,如果内存够就给这段内存标记一个编号. 2.擦除编号为 X的内存,erase X,  如果这段内存不存在那么输出“ILLEGAL_ERASE_ARGUMENT ”,否则什么都不输出. 3.整理内存,把所有的内存块整理到一块. #include<cstdio> #include<cstring> #include<iostream&g

Codeforce - 1191C - Tokitsukaze and Discard Items - 模拟

https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么呢?好像是每次都会删除干净的原因,从第一页开始考虑,第一页可以容纳到5,这个很显然. 删除之后有2个空位,然后可以容纳到7.再把7也删除,就可以容纳到8. 那么每次就暴力删除特殊元素就可以了,反正最多就是m个. 问题在于翻页的时候不能够简单的curpage++,这样必定翻车.我是直接二分,因为顶多就

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

Codeforces Round #264 (Div. 2) B

题目: B. Caisa and Pylons time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during

Codeforce 371A K-Periodic Array(模拟)

题目链接 K-Periodic Array 简单题,直接模拟即可. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define REP(i,n) for(int i(0); i < (n); ++i) 6 #define rep(i,a,b) for(int i(a); i <= (b); ++i) 7 const int N = 100000 + 10; 8 9 int a[N]; 10 int n, k; 11

codeforces A#264. Caisa and Sugar

Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are

Kilani and the Game-吉拉尼的游戏 CodeForce#1105d 模拟 搜索

题目链接:Kilani and the Game 题目原文 Kilani is playing a game with his friends. This game can be represented as a grid of size ??×??, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castle