C - Grand Garden

In a flower bed, there are NN flowers, numbered 1,2,......,N1,2,......,N. Initially, the heights of all flowers are 00. You are given a sequence h={h1,h2,h3,......}h={h1,h2,h3,......} as input. You would like to change the height of Flower kk to hkhk for all kk (1≤k≤N)(1≤k≤N), by repeating the following "watering" operation:

  • Specify integers ll and rr. Increase the height of Flower xx by 11 for all xx such that l≤x≤rl≤x≤r.

Find the minimum number of watering operations required to satisfy the condition.

Constraints

  • 1≤N≤1001≤N≤100
  • 0≤hi≤1000≤hi≤100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN
h1h1 h2h2 h3h3 ............ hNhN

Output

Print the minimum number of watering operations required to satisfy the condition.

Input

   

Output


Input

       

Output


题意:可以任意在区间【L,R】上加1,求通过最少次数得到题目给定的区间的值】

AC代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
];
signed  main(){
     ;
    int n;
    cin>>n;
    ;i<=n;i++)
        scanf("%lld",&arr[i]);
    ];
    ;i<=n;i++){
        if(i==n){  // 特判一下
            ans+=max(arr[i],temp);
        }else{
            if(arr[i]>=temp){
                temp=arr[i];
            }else{
                ans+=abs(arr[i]-temp);// 需要减去多加的数
                temp=arr[i];
            }
        }
    }
    cout<<ans;
    ;
}

代码2

#include<bits/stdc++.h>

using namespace std;
#define N 515155
int arr[N];

int main(){
  int n;
  cin>>n;
  ;
  scanf(]);
  ){
    cout<<arr[];
    ;
  }
  ];
  ;i<=n;i++){
    scanf("%d",&arr[i]);
    if(i==n){
      ans+=max(temp,arr[i]);
      break;
    }
    if(arr[i]<temp){
      ans+=temp-arr[i];
      temp=arr[i];
    }else{
      temp=arr[i];
    }
  }
  cout<<ans;
  ;
}

AtCoder Beginner Contest 116 C题 【题意:可以在任意区间【L,R】上加1,求通过最少加1次数得到题目给定的区间】】{思维好题}的更多相关文章

  1. AtCoder Beginner Contest 116 D - Various Sushi (贪心+栈)

    D - Various Sushi Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement ...

  2. AtCoder Beginner Contest 116 D - Various Sushi 【贪心+栈】

    Problem Statement There are NN pieces of sushi. Each piece has two parameters: "kind of topping ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  5. AtCoder Beginner Contest 224

    AtCoder Beginner Contest 224 A - Tires 思路分析: 判断最后一个字符即可. 代码如下: #include <bits/stdc++.h> using ...

  6. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  7. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

随机推荐

  1. spring cloud中代理服务器zuul的使用

    spring cloud中代理服务器zuul的使用 主流网关:     zuul     kong 基于nginx的API Gateway     nginx+lua 1.新建项目,选择eureka ...

  2. WUSTOJ 1208: 计算整数四则运算表达式的结果(Java)

    1208: 计算整数四则运算表达式的结果 参考资料 数据结构(C语言版)严蔚敏 吴伟民 编著----表达式求值 题目   简单四则运算.更多内容点击标题. 保证表达式合法. 运算符只包含:加(+),减 ...

  3. Python开发【第四章】:函数剖析

    一.Python函数剖析 1.函数的调用顺序 #!/usr/bin/env python # -*- coding:utf-8 -*- #-Author-Lian #函数错误的调用方式 def fun ...

  4. popcorn-js视频Video框架简单用法

    <div> <video class="video" id="ourvideobig" preload="auto" co ...

  5. sql注入测试(4)--如何防止该类缺陷发生

    检查用户输入的合法性,确信输入的内容只包含合法的数据,数据检查应当在客户端和服务器端都执行之所以要执行服务器端验证,是为了弥补客户端验证机制脆弱的安全性.在客户端,攻击者完全有可能获得网页的源代码,修 ...

  6. Windows下使用批处理文件.bat删除旧文件

    本文教大家写一个批处理文件.bat删除旧文件,供大家参考,具体内容如下 1. 批处理文件 del_old_file.bat rem 删除D:\temp目录下7天前的文件Forfiles /p E:\b ...

  7. js之split拆分字符串

    js之split拆分字符串 1.单字符拆分 let arr = str.split(',') 2.多字符拆分 let arr = str.split(/[(),]/)

  8. windows的一些常用指令

    持续更新中..... 1.清除系统内 DNS 的缓冲  :  nslookup baidu.com 2.修改hosts文件  :  位置 运行  ->  C:/windows/system32/ ...

  9. Windows10+Android Studio 3.5编译项目报错——NDK Resolution Outcome: Project settings: Gradle model version=4.10.1, NDK version is UNKNOWN

    项目背景: 系统有C.D两个盘,Android Studio安装在D盘,sdk安装在C盘. 出现的问题: 从git拉取项目后,一直编译不通过,提示“NDK Resolution Outcome: Pr ...

  10. dubbo线程池作用于接口而不是方法

    记一次线上dubbo服务超时和线程池满问题排查 可能调用的接口没问题,但是该服务中的其他接口占用完了线程池,导致调用超时被拒绝处理.