forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
35 lines (30 loc) · 972 Bytes
/
Solution.cpp
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
35
using pis = pair<int, string>;
class FoodRatings {
map<string, pis> mp;
map<string, set<pis>> t;
public:
FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) {
int n = foods.size();
for (int i = 0; i < n; ++i) {
string a = foods[i], b = cuisines[i];
int c = ratings[i];
mp[a] = pis(c, b);
t[b].insert(pis(-c, a));
}
}
void changeRating(string food, int newRating) {
pis& p = mp[food];
t[p.second].erase(pis(-p.first, food));
p.first = newRating;
t[p.second].insert(pis(-p.first, food));
}
string highestRated(string cuisine) {
return t[cuisine].begin()->second;
}
};
/**
* Your FoodRatings object will be instantiated and called as such:
* FoodRatings* obj = new FoodRatings(foods, cuisines, ratings);
* obj->changeRating(food,newRating);
* string param_2 = obj->highestRated(cuisine);
*/