-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefly.py
55 lines (37 loc) · 1.02 KB
/
firefly.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
width,height = map(lambda x: int(x), input().split(" "))
obstacleBot = []
obstacleTop = []
for i in range(width):
obstacle = int(input())
if i%2 == 0:
obstacleBot.append(obstacle)
elif i%2 == 1:
obstacleTop.append(obstacle)
obstacleBot.sort()
obstacleTop.sort()
def binarySearch(currHeight, obstacles):
left = 0
right = width//2
# print(currHeight)
# print(obstacles)
while(left<right):
midPoint = int((left+right)//2)
if obstacles[midPoint] < currHeight:
left = midPoint+1
else:
right = midPoint
return width//2-left
# answers = []
# length = len(obstacles)
minObstacles = float("inf")
count = 0
for i in range(1, height+1):
answerBot = binarySearch(i, obstacleBot)
answerTop = binarySearch(height-i+1, obstacleTop)
answer = answerTop+answerBot
if answer < minObstacles:
count = 1
minObstacles = answer
elif answer == minObstacles:
count = count+1
print(minObstacles, count)