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 ...
随机推荐
- Hadoop入门进阶步步高(一)-环境准备
前言 Hadoop从存储上来说,是相似于冗余磁盘阵列(RAID)的存储方式.将数据分散存储并提供以提供吞吐量,它的存储系统就是HDFS(Hadoop Distuibute Fils System).从 ...
- 【编码格式错误】SyntaxError: Non-UTF-8 code starting with
问题: SyntaxError: Non-UTF-8 code starting with '\xba' in file E:/placement/placement/Placement Test/c ...
- HTML的表单form以及form内部标签
<html> <head> <title> form表单的使用 </title> <!-- 标签名称:form 表单标签 属性:action:提交 ...
- luogu3376 【模板】 网络最大流
题目大意 给出一个网络图,以及其源点和汇点,求出其网络最大流. 概念 可以把网络图看作管道,节点看作管道的交界处.流就像是管道里的流水.管道有个容量(相当于横截面积),还会有个流量(相当于水流占了管道 ...
- Swift 3 关于Date的一些操作
前言 最近在写关于日期的一些操作,所以整理了一下这方面的一些知识 本Demo使用的是playground. 我们以前使用的都是NSDate类进行日期的操作,在Swift 3.0中,我们就可以使用更加S ...
- TensorFlow-mnist
训练代码: from __future__ import absolute_import from __future__ import division from __future__ import ...
- js+css模仿打字效果
1.效果 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %> ...
- 开发手机APP过程,不同使用场景APP搜索框的样式及区别
搜索框是 app 内最常见的控件之一,可以帮助用户快速又精准找到期望的内容与功能.不同的使用场景下,根据页面中搜索的重要程度,搜索框也有着不同的样式. 下面就常州开发APP公司和大家聊聊常见的四种样式 ...
- Spring AOP理解
Spring的核心思想的IOC和AOP.最近学习AOP,对切面的学习有了进一步的认识. Spring用代理类包裹切面,把他们织入到Spring管理的bean中.也就是说代理类伪装成目标类,它会截取对目 ...
- HDL之Bitwise operation
1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...