/*
CF789C. Functions again
http://codeforces.com/contest/789/problem/C
水题
题意:求数组中的连续和的最大值
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
//#define test
using namespace std;
const int Nmax=1e6;
int num[Nmax];
int num1[Nmax];
int num2[Nmax];
long long ans1,ans2;
int main()
{
#ifdef test
#endif
int n;
//freopen("test.in","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&num[i]);
}
for(int i=;i<n;i++)
num[i]=abs(num[i]-num[i+]);
for(int i=;i<n;i++)
{
if(i&)
num1[i]=num[i],num2[i]=-num[i];
else
num1[i]=-num[i],num2[i]=num[i];
}
//for(int i=1;i<n;i++)
//printf("%d %d\n",num1[i],num2[i]);
ans1=ans2=0LL;
long long tmp=0LL;
for(int i=;i<n;i++)
{
tmp+=1LL*num1[i];
if(tmp>ans1)
ans1=tmp;
if(tmp<0LL)
tmp=0LL;
}
tmp=;
for(int i=;i<n;i++)
{
tmp+=1LL*num2[i];
//printf("i:%d tmp:%d\n",i,tmp);
if(tmp>ans2)
ans2=tmp;
if(tmp<0LL)
tmp=0LL;
}
printf("%lld\n",max(ans1,ans2));
return ;
}

CF789C. Functions again的更多相关文章

  1. 【cf789C】Functions again(最大子序列和)

    C.Functions again 题意 给你一个数组a[1..n].有一个函数\(f(l,r)=\sum_{i=l}^{r-1}\left| a[i]-a[i+1]\right| (-1)^{l-i ...

  2. asp.net MVC helper 和自定义函数@functions小结

    asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...

  3. 【跟着子迟品 underscore】Array Functions 相关源码拾遗 & 小结

    Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...

  4. 【跟着子迟品 underscore】Object Functions 相关源码拾遗 & 小结

    Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...

  5. ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)

    一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...

  6. QM模块包含主数据(Master data)和功能(functions)

    QM模块包含主数据(Master data)和功能(functions)   QM主数据   QM主数据 1 Material   Master MM01/MM02/MM50待测 物料主数据 2 Sa ...

  7. jQuery String Functions

    In today's post, I have put together all jQuery String Functions. Well, I should say that these are ...

  8. 2-4. Using auto with Functions

    在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...

  9. [Python] Pitfalls: About Default Parameter Values in Functions

    Today an interesting bug (pitfall) is found when I was trying debug someone's code. There is a funct ...

随机推荐

  1. 解决solr搜索多词匹配度和排序方案

    转载请标明出处:http://blog.csdn.net/hu948162999/article/details/47727159 本文主要介绍了在短语.句子.多词查询中.solr在控制查询命中数量. ...

  2. HDU3535 AreYouBusy 混合背包

    题目大意 给出几组物品的体积和价值,每组分为三种:0.组内物品至少选一个:1.组内物品最多选一个:2.组内物品任意选.给出背包容量,求所能得到的最大价值. 注意 仔细审题,把样例好好看完了再答题,否则 ...

  3. Endnote导入共享数据

    Endnote导入共享数据 Endnote是我们经常使用的参考文献管理工具.但是,在云计算还不是很普及的今天,往往每台电脑上都有自己的endnote数据库.这样,换了电脑,要使用同样的参考文献数据时, ...

  4. 如何将本地代码上传到Github

    这些内容只是Git知识的冰山一角 更多知识请 阅读 Pro git.Pro git 所有内容均根据知识共享署名非商业性共享3.0版许可证授权,各位可以免费下载阅读,有pdf.mobi.qpub格式可以 ...

  5. JAVA 中for-each循环使用方法

    for each循环还是第一次见,“java SE 5.0增加了一种功能很强的循环结构,可以用来一次处理数组中的每个元素(其他类型的元素集合亦可)而不必为指定下标值而分心”. 这种增强的for eac ...

  6. NOIP2013 D1T3 货车运输

    [NOIP2013T3]货车运输 背景 noip2013day1 描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重 量限制,简称限重.现在有 q 辆货 ...

  7. 深度讲解智能硬件手机APP开发流程

    常州做APP开发公司紫竹云科技分析,智能硬件产品的软件开发,除了APP和后台之外还有一个固件端的开发,由于固件是要运行产品上的,不过此时的硬件也是刚开始进行研发,所以是无法提供硬件来运行固件的.因此在 ...

  8. 详解sqlserver查询表索引

    SELECT   索引名称=a.name ,表名=c.name ,索引字段名=d.name ,索引字段位置=d.colid ? 1 2 3 4 5 6 7 8 FROM  sysindexes  a ...

  9. sql server<> != 从数据类型varchar转换为numeric 时出错

    sql server 数据类型转换出错 字段percentcomplete 是 varchar 类型, 都是存的数字 用 where cast(percentcomplete as numeric(1 ...

  10. Cython入门.VS.C++

    原文链接:http://blog.csdn.net/gzlaiyonghao/article/details/4561611 作者:perrygeo 译者:赖勇浩(http://laiyonghao. ...