1
+ # Runtime: 4131 ms (Top 50.00%) | Memory: 98.7 MB (Top 51.92%)
1
2
import sortedcontainers as sc
2
3
class MovieRentingSystem :
3
- def __init__ (self , n : int , entries : List [List [int ]]):
4
- self .rented = sc .SortedList () # Triples of price, shop, movie
5
- self .movies = {} # Dictionary mapping movie -> sorted list of (price, shop)
6
- self .movie_and_shop_to_price = {} # Dictionary mapping (movie, shop) -> price
4
+ def __init__ (self , n : int , entries : List [List [int ]]):
5
+ self .rented = sc .SortedList () # Triples of price, shop, movie
6
+ self .movies = {} # Dictionary mapping movie -> sorted list of (price, shop)
7
+ self .movie_and_shop_to_price = {} # Dictionary mapping (movie, shop) -> price
7
8
8
- for shop , movie , price in entries :
9
- if movie not in self .movies :
10
- self .movies [movie ] = sc .SortedList ()
11
- self .movies [movie ].add ((price , shop ))
12
- self .movie_and_shop_to_price [movie , shop ] = price
9
+ for shop , movie , price in entries :
10
+ if movie not in self .movies :
11
+ self .movies [movie ] = sc .SortedList ()
12
+ self .movies [movie ].add ((price , shop ))
13
+ self .movie_and_shop_to_price [movie , shop ] = price
13
14
14
- def search (self , movie : int ) -> List [int ]:
15
- if movie not in self .movies :
16
- return []
17
- return [x [1 ] for x in self .movies [movie ][:5 ]] # Returning the shop numbers
15
+ def search (self , movie : int ) -> List [int ]:
16
+ if movie not in self .movies :
17
+ return []
18
+ return [x [1 ] for x in self .movies [movie ][:5 ]] # Returning the shop numbers
18
19
19
- def rent (self , shop : int , movie : int ) -> None :
20
- my_price = self .movie_and_shop_to_price [movie , shop ]
21
- self .rented .add ((my_price , shop , movie ))
22
- self .movies [movie ].remove ((my_price , shop ))
20
+ def rent (self , shop : int , movie : int ) -> None :
21
+ my_price = self .movie_and_shop_to_price [movie , shop ]
22
+ self .rented .add ((my_price , shop , movie ))
23
+ self .movies [movie ].remove ((my_price , shop ))
23
24
24
- def drop (self , shop : int , movie : int ) -> None :
25
- my_price = self .movie_and_shop_to_price [movie , shop ]
26
- self .rented .remove ((my_price , shop , movie ))
27
- self .movies [movie ].add ((my_price , shop ))
25
+ def drop (self , shop : int , movie : int ) -> None :
26
+ my_price = self .movie_and_shop_to_price [movie , shop ]
27
+ self .rented .remove ((my_price , shop , movie ))
28
+ self .movies [movie ].add ((my_price , shop ))
28
29
29
- def report (self ) -> List [List [int ]]:
30
- return [x [1 :] for x in self .rented [:5 ]] # Returning the (shop, movie) pairs
30
+ def report (self ) -> List [List [int ]]:
31
+ return [x [1 :] for x in self .rented [:5 ]] # Returning the (shop, movie) pairs
0 commit comments