-
Notifications
You must be signed in to change notification settings - Fork 0
/
d12.py
250 lines (201 loc) · 5.18 KB
/
d12.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# # Where is the Marble
# def find_marble(marbles, left, right, query):
# if left <= right:
# mid = left + (right - left) // 2
# if marbles[mid] == query and (mid == left or query > marbles[mid - 1]):
# return mid
# elif marbles[mid] < query:
# return find_marble(marbles, mid + 1, right, query)
# else:
# return find_marble(marbles, left, mid - 1, query)
# return -1
# case = 0
# while True:
# n, q = list(map(int, input().split()))
# if n == 0 and q == 0:
# break
# case += 1
# marbles = []
# for i in range(n):
# marble = int(input())
# marbles.append(marble)
# marbles.sort()
# print('CASE# {}:'.format(case))
# for _ in range(q):
# query = int(input())
# result = find_marble(marbles, 0, n - 1, query)
# if result == -1:
# print('{} not found'.format(query))
# else:
# print('{} found at {}'.format(query, result + 1))
# # Pizzamania
# t = int(input())
# for _ in range(t):
# n, m = list(map(int, input().split()))
# array = list(map(int, input().split()))
# array.sort()
# start = 0
# tail = n - 1
# count = 0
# while tail > start:
# sum = array[tail] + array[start]
# if sum == m:
# count += 1
# tail -= 1
# start += 1
# elif sum > m:
# tail -= 1
# else:
# start += 1
# print(count)
# # Eko
# import math
# N, M = list(map(int, input().split()))
# heights_of_tree = list(map(int, input().split()))
# heights_of_tree.append(0)
# N += 1
# heights_of_tree.sort()
# t = 0
# sum = 0
# result = 0
# for i in range(N - 1, -1, -1):
# t += 1
# sum += heights_of_tree[i]
# if sum - heights_of_tree[i] * t < M:
# continue
# elif sum - heights_of_tree[i] * t == M:
# result = (sum - M) / t
# break
# else:
# result = (sum - heights_of_tree[i] - M) // (t - 1)
# break
# print(math.floor(result))
# # The Playboy Chimp
# # https://onlinejudge.org/external/106/10611.pdf
# import bisect
# def bs_first(a, left, right, x):
# if left < right:
# mid = (left + right) // 2
# if (mid == left or x > a[mid - 1]) and a[mid] == x:
# return mid
# elif x > a[mid]:
# return bs_first(a, mid + 1, right, x)
# else:
# return bs_first(a, left, mid - 1, x)
# return -1
# def bs_last(a, left, right, x):
# if left < right:
# mid = (left + right) // 2
# if (mid == right or x < a[mid + 1]) and a[mid] == x:
# return mid
# elif x < a[mid]:
# return bs_first(a, left, mid - 1, x)
# else:
# return bs_first(a, mid + 1, right, x)
# return -1
# N = int(input())
# heights_of_chimps = list(map(int, input().split()))
# Q = int(input())
# queries = list(map(int, input().split()))
# for query in queries:
# r1 = 'X'
# r2 = 'X'
# left = bisect.bisect_left(heights_of_chimps, query)
# right = bisect.bisect_right(heights_of_chimps, query)
# if right != N:
# r2 = heights_of_chimps[right]
# if left > 0:
# r1 = heights_of_chimps[left - 1]
# print('{} {}'.format(r1, r2))
# # The Monkey and the Oiled Bamboo - https://onlinejudge.org/external/120/12032.pdf
# T = int(input())
# for t in range(T):
# n = int(input())
# r = list(map(int, input().split()))
# if len(r) == 1:
# print('Case {}: {}'.format(t + 1, r[0]))
# continue
# steps = []
# for j in range(len(r)):
# if j != len(r) - 1:
# steps.append(r[j + 1] - r[j])
# steps.append(r[0])
# steps.sort()
# result = steps[-1]
# for i in range(len(steps) - 1, -1, -1):
# if result == steps[i]:
# result -= 1
# if result > 0:
# result = steps[-1]
# elif result == 0:
# result = steps[-1] + 1
# else:
# result = steps[-1] - result
# print('Case {}: {}'.format(t + 1, result))
# # Other solution:
# T = int(input())
# for tc in range(1, T + 1):
# print('Case %d: ' % tc, end = '')
# n = int(input())
# a = [0] + list(map(int, input().split()))
# l = 1
# r = a[-1] + 1
# res = 0
# while l <= r:
# mid = (l + r) // 2
# k = mid
# check = True
# for i in range(n + 1):
# if a[i] - a[i - 1] > k:
# check = False
# break
# else:
# if a[i] - a[i - 1] == k:
# k -= 1
# if check:
# res = mid
# r = mid - 1
# else:
# l = mid + 1
# print(res)
# # Hacking the random number generator
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# a.sort()
# res = 0
# j = 0
# def bs_search(a, l, r, value):
# while l <= r:
# mid = int( (l + r) / 2 )
# if a[mid] == value:
# return True
# if a[mid] > value:
# r = mid - 1
# else:
# l = mid + 1
# return False
# for i in range(n):
# # while j < i and a[i] - a[j] > k:
# # j += 1
# # if a[i] - a[j] == k:
# # res += 1
# if bs_search(a, i + 1, n - 1, a[i] + k):
# res += 1
# print(res)
# Energy Exchange
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
sum_energy = sum(a)
left = 0
right = 1000
while right - left > 1e-7:
mid = (left + right) / 2
sum_tranfer = 0
for x in a:
if x > mid:
sum_tranfer += x - mid
if mid * n < sum_energy - sum_tranfer * k / 100:
left = mid
else:
right = mid
print('%.9f' % left)