1
class MovieRentingSystem {3
Map<Integer, Map<Integer, Pair>> map = new HashMap<>();5
TreeSet<Pair> rented = new TreeSet<>(new rcomp());7
public MovieRentingSystem(int n, int[][] entries) {8
for (int entry[] : entries) {9
Map<Integer, Pair> map1 = map.getOrDefault(entry[1], new HashMap<>());10
Pair p = new Pair(entry[0], entry[1], entry[2]);11
map1.put(entry[0], p);12
map.put(entry[1], map1);16
public List<Integer> search(int movie) {18
PriorityQueue<Pair> pq = new PriorityQueue<>(new scomp());20
Map<Integer, Pair> map1 = map.getOrDefault(movie, new HashMap<>());22
for (Pair p : map1.values()) {29
if (pq.peek().price > p.price) {32
} else if (pq.peek().price == p.price && pq.peek().shop > p.shop) {39
List<Integer> ans = new ArrayList<>();41
while (!pq.isEmpty()) {50
public void rent(int shop, int movie) {52
Pair p = map.get(movie).get(shop);57
public void drop(int shop, int movie) {58
Pair p = map.get(movie).get(shop);63
public List<List<Integer>> report() {64
List<List<Integer>> ans = new ArrayList<>();66
for (Pair p : rented) {67
List<Integer> t = new ArrayList<>();71
if (ans.size() == 5) {80
class scomp implements Comparator<Pair> {82
public int compare(Pair a, Pair b) {83
if (a.price == b.price) {84
return b.shop - a.shop;86
return b.price - a.price;90
class rcomp implements Comparator<Pair> {91
public int compare(Pair a, Pair b) {92
if (a.price == b.price) {93
if (a.shop == b.shop) {94
return a.movie - b.movie;96
return a.shop - b.shop;98
return a.price - b.price;109
Pair(int shop, int movie, int price) {116
public int hashCode() {117
return Objects.hash(shop, movie, price);120
public boolean equals(Object obj) {121
Pair obj1 = (Pair) obj;122
if (obj1.shop == shop && obj1.movie == movie && obj1.price == price) {