mirror of
https://github.com/iritmaximus/tira.git
synced 2026-10-12 19:13:47 +03:00
24 lines
484 B
Python
24 lines
484 B
Python
from heapq import heappush, heappop
|
|
|
|
|
|
class Tasks:
|
|
def __init__(self):
|
|
self.heap = []
|
|
|
|
def add(self, name, priority):
|
|
heappush(self.heap, (-1 * priority, name))
|
|
|
|
def next(self):
|
|
return heappop(self.heap)[1]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
t = Tasks()
|
|
t.add("siivous", 10)
|
|
t.add("ulkoilu", 50)
|
|
t.add("opiskelu", 50)
|
|
print(t.next()) # opiskelu
|
|
t.add("treffit", 100)
|
|
print(t.next()) # treffit
|
|
print(t.next()) # ulkoilu
|