-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1912-Design-Movie-Rental-System.py
More file actions
34 lines (27 loc) · 1.25 KB
/
1912-Design-Movie-Rental-System.py
File metadata and controls
34 lines (27 loc) · 1.25 KB
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
class MovieRentingSystem:
def __init__(self, n: int, entries: List[List[int]]):
self.available = {}
self.rented = SortedList()
self.shop_movie_price = {(shop, movie): price for shop, movie, price in entries}
for shop, movie, price in entries:
if movie not in self.available:
self.available[movie] = SortedList()
self.available[movie].add((price, shop))
def search(self, movie: int) -> List[int]:
return [shop for _, shop in self.available.get(movie, [])[:5]]
def rent(self, shop: int, movie: int) -> None:
price = self.shop_movie_price[(shop, movie)]
self.available[movie].remove((price, shop))
self.rented.add((price, shop, movie))
def drop(self, shop: int, movie: int) -> None:
price = self.shop_movie_price[(shop, movie)]
self.rented.remove((price, shop, movie))
self.available[movie].add((price, shop))
def report(self) -> List[List[int]]:
return [[shop, movie] for _, shop, movie in self.rented[:5]]
# Your MovieRentingSystem object will be instantiated and called as such:
# obj = MovieRentingSystem(n, entries)
# param_1 = obj.search(movie)
# obj.rent(shop,movie)
# obj.drop(shop,movie)
# param_4 = obj.report()