-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathl_two_bicycles.py
57 lines (44 loc) · 1.29 KB
/
l_two_bicycles.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
from bisect import bisect_left
def binary_search(a: list[int], k: int) -> int:
left, right = 0, len(a)
while left < right:
mid = (left + right) // 2
if a[mid] == k:
return mid
if a[mid] > k:
right = mid
else:
left = mid + 1
return -1
DAY_OFFSET = 1
def left_binary_search(a: list[int], k: int) -> int:
left, right = 0, len(a) - 1
while left < right:
mid = (left + right) // 2
if a[mid] >= k:
right = mid
else:
left = mid + 1
return left + DAY_OFFSET if a and a[left] >= k else -1
def left_binary_search_rec(a: list[int], k: int) -> int:
def rec(left: int, right: int):
if left > right:
return -1
mid = (left + right) // 2
if a[mid] >= k:
if left == mid:
return mid + DAY_OFFSET
return rec(left, mid)
return rec(mid + 1, right)
return rec(0, len(a) - 1)
def bisect(a: list[int], k: int) -> int:
pos = bisect_left(a, k)
return pos + DAY_OFFSET if pos < len(a) else -1
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
cost = int(input())
print(
left_binary_search(a, cost),
left_binary_search(a, 2 * cost),
)