B. Wilbur and Array
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn.

Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input.

The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).

Output

Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.

Examples
input
5
1 2 3 4 5

output
5

input
4
1 2 2 1

output
3

Note

In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.

In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract1.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=200010;
long long num[maxn];
int main()
{int n;long long ans;scanf("%d",&n);ans=0;for(int i=1;i<=n;++i){scanf("%lld",&num[i]);ans=ans+abs(num[i]-num[i-1]);}printf("%lld\n",ans);return 0;
}

cf596B. Wilbur and Array相关推荐

  1. Wilbur and Array

    Wilbur and Array Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...

  2. CodeForces 596B Wilbur and Array 贪心

    给出原始{ai}={0},{bi}.每次修改{ai..n}+1或-1,求最小操作次数使{ai}=={bi}. 累计相邻两数差即可. 因为差最大10^9,数字有2*10^5,要long long. #i ...

  3. B. Wilbur and Array

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. cf B. Wilbur and Array

    Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting ...

  5. CodeForces 596 B Wilbur and Array

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  6. CodeForces 596B Wilbur and Array

    简单题,一个一个操作,最后就是答案. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  7. 老男孩上海校区Python面试题

    python面试题 第一章:python基础 数据类型: 1 字典: 1.1 现有字典 dict={'a':24,'g':52,'i':12,'k':33}请按字典中的 value 值进行排序? 1. ...

  8. php recordarray,Array 数组 - [ php中文手册 ] - 在线原生手册 - php中文网

    用户评论: [#1] florenxe [2015-10-07 18:53:45] //a nice little way to print leap years using array for ($ ...

  9. NumPy — 创建全零、全1、空、arange 数组,array 对象类型,astype 转换数据类型,数组和标量以及数组之间的运算,NumPy 数组共享内存

    NumPy 简介 一个用 python 实现的科学计算包.包括: 1.一个强大的 N 维数组对象 Array : 2.比较成熟的(广播)函数库: 3.用于整合 C/C++ 和 Fortran 代码的工 ...

最新文章

  1. bzoj3514(LCT+主席树)
  2. 【Unity笔记】使用协程(Coroutine)异步加载场景
  3. mysql 从库 read only_mysql salve从库设置read only 属性
  4. RabbitMQ集群、镜像部署配置
  5. python怎么导入大小字母_isort-用于对python导入的库按照字母进行排序的工具
  6. 360浏览器或chrome谷歌浏览器 打不开HTTPS网站,显示您的连接不是私密连接解决办法
  7. VHDL——分频器设计
  8. 注册表 关闭打印机服务器,win7系统添加打印机无Print Spooler服务无注册表的解决方法...
  9. 厦门大学计算机科学夏令营过程,厦门大学信息学院计算机系夏令营学生见面会如期召开-厦门大学计算机科学系...
  10. 全球及中国吊链总成行业研究及十四五规划分析报告
  11. Android实现手机静音,Android实现手机静音
  12. 计算机比赛小组名称和口号,小组名称口号大全(精选150个)
  13. php 获取京东商品详情,用正则表达式,抓取京东的商品列表
  14. 基于惯性传感器的轨迹记录系统
  15. 汽车厂商 API数据接口
  16. Centos7编译安装Xen环境(vtpm)
  17. 硬件设计——不一二电路设计(电源电路、接口电路、时钟电路)
  18. 15/18位身份证号码正则表达式(详细版)
  19. three.js绘制波浪面_使用Three.js构建建筑物波浪动画
  20. Mysql基础知识罗列

热门文章

  1. DEFCON 20 CTF 磁盘取证分析题目
  2. iOS 当APP接收到推送消息时,对推送消息进行处理
  3. password MD5加密方法
  4. 自问自答系列——商城相关
  5. threejs粒子效果
  6. Maltrail恶意流量检测系统
  7. nginx和ftp搭建图片服务器
  8. 计算机地理绘图软件叫什么,地理教师如何选择理想的绘图软件 ──基于对常用绘图软件的比较与分析...
  9. So easy ! 两句口号轻松搞懂Docker
  10. 通过算法理解,把字符串转换成整形数字