Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions binary-search-for-the-answer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def check(x, k, arr):
dots = 1
right_dot = arr[0]
for it in arr:
if it - right_dot >= x:
dots += 1
right_dot = it
if dots >= k:
return True
else:
return False


if __name__ == '__main__':
n = int(input())
k = int(input()) + 1
array = []
for _ in range(n):
array.append(int(input()))
left = 0
right = array[-1] - array[0]
if not check(right, k, array):
while right - left > 1:
mid = (left + right) // 2
if check(mid, k, array):
left = mid
else:
right = mid
print(left)
else:
print(right)
6 changes: 6 additions & 0 deletions binary-search-tree/1.contains.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-
-
+
-
+
-
7 changes: 7 additions & 0 deletions binary-search-tree/1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
6
417
274
417
53
274
89
6 changes: 6 additions & 0 deletions binary-search-tree/1.min-after.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- -
- 417
+ -
- 274
+ 417
- 274
20 changes: 20 additions & 0 deletions binary-search-tree/2.contains.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-
-
-
-
-
-
+
-
-
-
+
-
+
-
-
-
-
-
+
-
21 changes: 21 additions & 0 deletions binary-search-tree/2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
1223
1855
893
1584
918
1499
918
143
1799
646
1223
179
1584
335
208
3
773
502
773
13
20 changes: 20 additions & 0 deletions binary-search-tree/2.min-after.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- -
- -
- 1223
- 1855
- 1223
- 1584
+ 1223
- 893
- 1855
- 893
+ 1499
- 646
+ 1799
- 646
- 335
- 143
- 893
- 646
+ 893
- 143
Loading