From f05d888a0b621ca4e99e2b0fb6e23c097006fe41 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 28 May 2024 10:29:13 +0200 Subject: Init --- progs/unparsable_programs/a705.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 progs/unparsable_programs/a705.py (limited to 'progs/unparsable_programs/a705.py') diff --git a/progs/unparsable_programs/a705.py b/progs/unparsable_programs/a705.py new file mode 100644 index 0000000..a0b26fe --- /dev/null +++ b/progs/unparsable_programs/a705.py @@ -0,0 +1,26 @@ +from heapq import heappop, heappush +class Node: + def __init__(self, value, list_num, index): + self.value = value + self.list_num = list_num + self.index = index + def __lt__(self, other): + return self.value < other.value +def find_minimum_range(list): + high = float('-inf') + p = (0, float('inf')) + pq = [] + for i in range(len(list)): + heappush(pq, Node(list[i][0], i, 0)) + high = max(high, list[i][0]) + while True: + top = heappop(pq) + low = top.value + i = top.list_num + j = top.index + if high - low < p[1] - p[0]: + p = (low, high) + if j == len(list[i]) - 1: + return p + heappush(pq, Node(list[i][j + 1], i, j + 1)) + high = max(high, list[i][j + 1]) \ No newline at end of file -- cgit v1.2.3-18-g5258