-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.py
More file actions
37 lines (26 loc) · 708 Bytes
/
printer.py
File metadata and controls
37 lines (26 loc) · 708 Bytes
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
import os
def _binary_search(n: int, f: callable):
r = n
l = -1
while r - l > 1:
mid = (r + l) // 2
if f(mid):
l = mid
else:
r = mid
if f(r):
return r
return l
def build_monitor(a: tuple):
_count = min(a[0], a[1]) + min(a[2], a[3])
return _binary_search(_count // 2, lambda i: i * i <= _count)
f = open("test.txt")
if __name__ == "__main__":
fptr = open(
os.environ["OUTPUT_PATH"] if "OUPTUT_PATH" in os.environ else "test_result.log",
"w",
)
a = tuple([int(x) for x in f.readline().rstrip().split()])
result = build_monitor(a)
print(result)
fptr.write(str(result) + "\n")