/*
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. leetCode 74.Search a 2D Matrix(搜索二维矩阵) 解题思路和方法

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  2. cmd执行调用打开文件

    Process p = new Process();//新进程 p.StartInfo.FileName = "cmd.exe";//打开cmd程序 p.StartInfo.Use ...

  3. AES 加密位: 128位,加密模式:CBC, 填充模式:Zeros

    // AES 加密 public byte[] AESEncrypt(string text) { byte[] data = Encoding.Unicode.GetBytes(text); Sym ...

  4. 控制台中使用SetTimer的提醒

    SetTimer是设置定时器,每隔一段时间执行一个操作,原型如下 UINT_PTR SetTimer( HWND hWnd, // 窗口句柄 UINT_PTR nIDEvent, // 定时器ID,多 ...

  5. “Parsing filters unsupported” error during extraction of RAR file

    up vote 159 down vote accepted You can use: sudo apt-get install unrar or sudo apt-get install unar ...

  6. Linux - 控制台界面,虚拟界面,字符界面

    tty控制台终端. pts虚拟终端. tty1 图形界面. tty2 字符界面. Ctrl+Alt+F2-6 在字符界面下,通过Alt+F2 切换回来.或者切换到其他的字符界面. Alt+F2 pts ...

  7. [JavaEE] DWR框架实现Ajax

    Ajax是时下比较流行的一种web界面设计新思路,其核心思想是从浏览器获取XMLHttp对象与服务器端进行交互. DWR(Direct Web Remoting)就是实现了这种Ajax技术的一种web ...

  8. js中的面向对象(一)封装

    1.简单的封装(定义) var cat1 = {}; cat1.name = '阿黄'; cat1.sex = '男'; cat1.age = 11; //cat2也同样具有三个属性 var cat2 ...

  9. c语言递归讲解分析

    C语言允许函数调用它自己,这种调用的过程称为"递归(recursion)" 举例说明,如下代码: #include <stdio.h> void up_and_down ...

  10. linux 免密登陆(超简单)

    一.客户端生产公钥 在windwos上 生成公钥私钥前,先下载git哦 ssh-keygen -t rsa# 记住下方方框内公钥保存地址, 二.查看自己用户的登录地址 cat /etc/passwd ...