Code by a participant O(n log n)
from heapq import heappop, heapify, heappush
class Solution:
def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int:
time = 0
n = len(dist)
ans = 0
heap = []
for i, d in enumerate(dist):
time_to_reach = math.ceil(d / speed[i])
if time_to_reach == 0:
return 0
heappush(heap, (time_to_reach, i))
while heap:
ttr, i = heappop(heap)
if ttr <= time:
return ans
ans += 1
time += 1
return n