-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtask6_7.py
78 lines (66 loc) · 1.2 KB
/
task6_7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from math import fabs
NN = 1000000
eps = 1e-7
h = [0 for _ in range(NN)]
def get_h():
global a, h, s
assert (s < t)
return a[h[s]]
def pop_h():
global s, h
assert (s < t)
s += 1
return h[s - 1]
def push_h(x):
global t, h, s, a
while s < t and a[h[t - 1]] < a[x]:
t -= 1
h[t] = x
t += 1
n, C = str(input()).split()
n = int(n)
C = float(C)
a = [0 for _ in range(NN)]
for i in range(n - 1):
a[i] = int(input())
p = [0 for i in range(n)]
s = 0
t = 0
i = 0
j = 1
l = C
r = 0
push_h(0)
while i < j < n and l > (a[j - 1] + eps):
ev1 = (l - r) * (j - i) / (j - i + 1)
if s < t:
ev2 = (l - get_h()) * (j - i)
ev = min(ev2, ev1)
else:
ev = ev1
l -= (ev / (j - i))
r += ev
if fabs(l - r) < eps:
push_h(j)
j += 1
r = 0
if fabs(l - get_h()) < eps:
x = pop_h()
while i <= x:
p[i] = l
i += 1
i = x + 1
if (i == j) or (l < a[j - 1] + eps):
while i < j:
p[i] = l
i += 1
l = r
r = 0
i = j
push_h(j)
j += 1
while i < j:
p[i] = l
i += 1
for i in range(n):
print(p[i])