-
-
Save pse1202/a01d5c1f094e1599836a to your computer and use it in GitHub Desktop.
Codeforces Round #320 Div2 E / Div1 C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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