题目描述:

E. Weakness and Poorness

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence of n integers a1, a2, ..., a**n.

Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., a**n - x is as small as possible.

The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.

The poorness of a segment is defined as the absolute value of sum of the elements of segment.

Input

The first line contains one integer n (1 ≤ n ≤ 200 000), the length of a sequence.

The second line contains n integers a1, a2, ..., a**n (|a**i| ≤ 10 000).

Output

Output a real number denoting the minimum possible weakness of a1 - x, a2 - x, ..., a**n - x. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Examples

Input

Copy

31 2 3

Output

Copy

1.000000000000000

Input

Copy

41 2 3 4

Output

Copy

2.000000000000000

Input

Copy

101 10 2 9 3 8 4 7 5 6

Output

Copy

4.500000000000000

Note

For the first case, the optimal value of x is 2 so the sequence becomes  - 1, 0, 1 and the max poorness occurs at the segment "-1" or segment "1". The poorness value (answer) equals to 1 in this case.

For the second sample the optimal value of x is 2.5 so the sequence becomes  - 1.5,  - 0.5, 0.5, 1.5 and the max poorness occurs on segment "-1.5 -0.5" or "0.5 1.5". The poorness value (answer) equals to 2 in this case.

思路:

这道题是要求一个数列减去一个数$x$后的子列和的绝对值最大(poorness)的情况下的可能的最小值(weakness)。(有点绕哈

Codeforces E. Weakness and Poorness(三分最大子列和)的更多相关文章

  1. [codeforces] 578C Weakness and Poorness || 三分

    原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...

  2. codeforces 578c - weekness and poorness - 三分

    2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...

  3. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp

    C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  4. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分

    E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)

    题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...

  6. cf578c Weakness and Poorness 三分

    其实三分就是一个求单峰函数的最值的东西,用法比较统一.这个题就是观察发现不美好值是一个单峰函数,然后枚举t进行三分就行了. 题干: 给定一个长度为n的数组ai,求一个实数x,使得序列a1-x,a2-x ...

  7. Codeforces 578.C Weakness and Poorness

    C. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. 【CodeForces】578 C. Weakness and Poorness

    [题目]C. Weakness and Poorness [题意]给定含n个整数的序列ai,定义新序列为ai-x,要使新序列的最大子段和绝对值最小,求实数x.n<=2*10^5. [算法]二分| ...

  9. PAT复杂度_最大子列和问题、最大子列和变种

    01-复杂度1. 最大子列和问题 给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j ...

随机推荐

  1. win7安装 nodejs,npm

    1. 下载地址:http://nodejs.org/dist/v9.7.1/ 2. 安装 3. 查看是否安装成功,命令行查询 node  -v 4. 默认已经安装了npm,直接查询版本 5. 配置np ...

  2. python进阶---列表、字典、集合相关操作

    基本概念 列表 序列是python中一个基本的数据结构,每个元素都有一个索引index 操作 # 创建列表 list = [] # 修改列表 list[2] = 2001 # 删除列表 del lis ...

  3. 【视频开发】opencv不能读取MP4格式文件

    用OpenCV对视频进行处理时,不能打开.mp4格式的文件.后来解决办法是用ffmpeg.exe将mp4文件转码为avi文件,然后再进行处理.但是转码过程比较慢.后来查看opencv源代码,发现它也是 ...

  4. spring security实现记录用户登录时间等信息

    目录 spring security实现记录用户登录时间等信息 一.原理分析 二.实现方式 2.1 自定义AuthenticationSuccessHandler实现类 2.2 在spring-sec ...

  5. 【剑指offer】1+….+n,不能使用相关关键字

    题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 分析:可以使用递归! class Soluti ...

  6. Django框架之第八篇(模型层补充)--数据库的查询与优化:only/defer,select_related与prefetch_related,事务

    在设置外键字段时需要注意: 当你使用django2.x的版本时候,在建立外键关系时,需要你手动添加几个关键点参数 models.cascade #设置级联删除 db_constraints 数据库查询 ...

  7. 第1课,python输出,输入,变量,运算

    课程内容: 为什么要学习python 如何学python 实践体验 图片来源网络分享 为什么要学python: 简单 (设计如此) 强大(因为开源,有库) 如何学习python: 变量 --> ...

  8. Linux 线程间的同步与互斥

    在线程并发执行的时候,我们需要保证临界资源的安全访问,防止线程争抢资源,造成数据二义性. 线程同步: 条件变量 为什么使用条件变量? 对临界资源的时序可控性,条件满足会通知其他等待操作临界资源的线程, ...

  9. VB.NET 读写XML

    Public Class CSysXML Dim mXmlDoc As New System.Xml.XmlDocument Public XmlFile As String Public Sub N ...

  10. F1 相似查找字段存在的table

    REPORT ZME12_BDC1. *REPORT demo_select_dynamic_conditions . TABLES: makt,dd02t,marc. TYPE-POOLS : AB ...