-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmost_popular_video_creator.cpp
66 lines (66 loc) · 1.69 KB
/
most_popular_video_creator.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
static const int __ = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
return 0;
}();
class Solution {
public:
vector<vector<string>> mostPopularCreator(vector<string> &creators,
vector<string> &ids,
vector<int> &views) {
int i, j;
int nc = creators.size();
int ni = nc;
int nv = nc;
long long int sum = 0;
vector<vector<string>> ans;
vector<string> str;
unordered_map<string, long long int> mp;
unordered_map<string, string> mp1;
for (i = 0; i < nc; i++) {
mp[creators[i]] = 0;
}
for (i = 0; i < nc; i++) {
mp[creators[i]] += views[i];
}
long long int mav = 0;
for (auto k : mp) {
mav = max(mav, k.second);
// cout<<k.first<<"\t"<<k.second<<endl;
}
// cout<<mav<<endl;
unordered_map<string, int> mi;
// int mai = 0;
for (auto k : mp) {
mp1[k.first] = "zzzzzzzzzz";
mi[k.first] = 0;
}
// for(i=0; i<nc; i++){
// mi[creators[i]] = 0;
// }
for (i = 0; i < nc; i++) {
if (views[i] > mi[creators[i]]) {
mp1[creators[i]] = ids[i];
mi[creators[i]] = views[i];
} else if (views[i] == mi[creators[i]]) {
mp1[creators[i]] = min(mp1[creators[i]], ids[i]);
// mi[creators[i]] = views[i];
}
}
// for(auto k:mp1){
// cout<<k.first<<"\t"<<k.second<<endl;
// }
for (auto k : mp) {
str.clear();
if (k.second == mav) {
str.push_back(k.first);
str.push_back(mp1[k.first]);
}
if (str.size() > 0) {
ans.push_back(str);
}
}
return ans;
}
};