from sortedcontainers import SortedList
class Checkout:
def __init__(self):
self.queue = collections.deque()
self.sortLink = SortedList()
def get_max(self) -> int:
if len(self.queue) == 0:
return -1
else:
v = self.sortLink.pop()
self.sortLink.add(v)
return v
def add(self, value: int) -> None:
self.queue.append(value)
self.sortLink.add(value)
def remove(self) -> int:
if len(self.queue) == 0:
return -1
else:
v = self.queue.popleft()
self.sortLink.remove(v)
return v
# Your Checkout object will be instantiated and called as such:
# obj = Checkout()
# param_1 = obj.get_max()
# obj.add(value)
# param_3 = obj.remove()