CF789C. Functions again
/*
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的更多相关文章
- 【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 ...
- asp.net MVC helper 和自定义函数@functions小结
asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...
- 【跟着子迟品 underscore】Array Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- 【跟着子迟品 underscore】Object Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- QM模块包含主数据(Master data)和功能(functions)
QM模块包含主数据(Master data)和功能(functions) QM主数据 QM主数据 1 Material Master MM01/MM02/MM50待测 物料主数据 2 Sa ...
- jQuery String Functions
In today's post, I have put together all jQuery String Functions. Well, I should say that these are ...
- 2-4. Using auto with Functions
在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...
- [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 ...
随机推荐
- [深入理解Android卷一全文-第七章]深入理解Audio系统
由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容. ...
- nyoj 21--三个水杯(隐式图bfs)
三个水杯 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子.三个水杯之间相互倒水,并且水杯没有标识 ...
- 关于chm提示 已取消到该网页的导航的解决方法
下载了一个chm文件,打开提示“已取消到该网页的导航”,以前以为是文件有问题,下载其他的也是出现这种情况,于是网上搜了下,解决方法如下: 方法 1 1. 双击此 .chm 文件. 2. 在“打开文件安 ...
- 整体刷新和局部刷新frameset窗口
在项目中,经常会遇到页面分割,最常见的系统或网站的主界面.主页面分为,上面系统简介.下面作者简介.左边系统功能菜单.右边则是菜单真正展示的界面. 遇到这种这种分割页面,大家首先想到是frameset, ...
- RoIPooling与RoIAlign的区别
一.RoIPooling与RoIAlign 1.1.RoIPooling 通过对Faster RCNN的学习我妈了解的RolPooling可以使生成的候选框region proposal映射产生固定大 ...
- levelDB数据库使用及实例 - 高性能nosql存储数据库
LevelDB是google公司开发出来的一款 超高性能kv存储引擎,以其惊人的读性能和更加惊人的写性能在轻量级nosql数据库中鹤立鸡群. 此开源项目目前是支持处理十亿级别规模Key-Value型数 ...
- WebService 服务接口
天气预报Web服务,数据来源于中国气象局Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmxDisco :http ...
- HDL之Bitwise operation
1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...
- BOW模型在ANN框架下的解释
原文链接:http://blog.csdn.net/jwh_bupt/article/details/17540561 作者的视野好,赞一个. 哥德尔第一完备性定理,始终是没有能看完完整的证明,艹!看 ...
- ML一:python的KNN算法
(1):list的排序算法: 参考链接:http://blog.csdn.net/horin153/article/details/7076321 示例: DisListSorted = sorted ...