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. mosquitto安装遇到问题和解决办法

    问题1 make编译报错,提示xsltproc命令未找到 解决办法: yum  install libxslt 问题2 make编译报错,提示: failed to load external ent ...

  2. 基于聚类K-Means方法实现图像分割

    ”“”K-Means to realize Image segmentation “”“ import numpy as np import PIL.Image as image from sklea ...

  3. php文件操作类

    <?php /** *本类为文件操作类,实现了文件的建立,写入,删除,修改,复制,移动,创建目录,删除目录 * 列出目录里的文件等功能,路径后面别忘了加"/" */ clas ...

  4. SAS学习笔记2 基础函数应用

    输入输出语句(put和input函数) put()函数:把数值型或字符型变量转为字符型变量(输出变量) input()函数:将字符型变量转化为数值型变量(输入变量) 选择与删除语句(keep.drop ...

  5. IMPDPORA-27046,dump文件损坏

    客户提出导入报错 一.报错如下 SYMPTOMS DataPump Import (IMPDP) fails with the following errors: ORA-: invalid oper ...

  6. svn之合并分支

    学习连接 svn的merge使用例子

  7. C#通过地址获取省市区(基于百度地图API)

    最近公司有个需求,想通过地址获取对应的省市区,本来想直接通过对地址的截取,对于完整的地址还可以,不完整的就没法用了 所以本篇通过百度地图API来获取地址 第一步:申请ak密钥 登录百度地图开放平台,按 ...

  8. 配置vue 多页面

    安装vue 1. 全局安装 vue-cli环境 npm install --global vue-cli 2. 创建一个基于webpack模板的新项目 vue init webpack my-proj ...

  9. 根据导入xlxs的文件,来写入数据库

    今天讲解一下上传文件.前台必须保持传参类型"multipart/form-data" 后台可以设定 public static final String MULTIPART_FOR ...

  10. init system

    参考:5 Best Modern Linux ‘init’ Systems (1992-2015) 参考:Linux开机流程 参考:<鸟哥的 Linux 私房菜:基础学习篇 第四版>第十七 ...