Skip to content

Instantly share code, notes, and snippets.

@pse1202

pse1202/E.py Secret

Created September 16, 2015 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pse1202/a01d5c1f094e1599836a to your computer and use it in GitHub Desktop.
Save pse1202/a01d5c1f094e1599836a to your computer and use it in GitHub Desktop.
Codeforces Round #320 Div2 E / Div1 C
n = input()
d = list(map(int,raw_input().split(" ")))
s = d[:]
for i in range(len(d)):
if(i>0):
s[i] = s[i-1] + d[i]
l = min(d)
ll = l
r = max(d)
rr = r
step = 1.0
def weak(x):
ss = [0] + [s[i] - x*(1+i) for i in range(len(s))]
return max(ss) - min(ss)
t = True
x = 0
while(abs(ll-rr) > 10**(-6)):
if t:
k = l
else:
k = r
x = k + step
if(weak(x) < weak(k)):
if t:
l = x
else:
r = x
else:
if t:
rr = x
l = ll
else:
ll = x
r = rr
t = not t
step *= -0.5
x = (ll+rr)/2.0
print weak(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment