-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd62_q1a_vote.cpp
46 lines (42 loc) · 1.18 KB
/
d62_q1a_vote.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
#include <iostream>
#include <set>
#include <map>
int main(){
std::ios_base::sync_with_stdio(false); std::cin.tie(0);
int N,K;
std::string person;
std::map<int,std::set<std::string>> scoreReverse;
std::map<std::string,int> score;
std::cin >> N >> K;
while (N--){
std::cin >> person;
if(score.find(person) != score.end()){
score[person] += 1;
scoreReverse[score[person]].insert(person);
scoreReverse[score[person]-1].erase(person);
if (scoreReverse[score[person]-1].empty()){
auto x = scoreReverse.find(score[person]-1);
scoreReverse.erase(x);
}
} else {
scoreReverse[1].insert(person);
score[person] = 1;
}
}
int sum = 0;
bool b = true;
for(auto it = scoreReverse.end() ; it != scoreReverse.begin() ; it--){
if(it == scoreReverse.end()){
continue;
}
sum += it->second.size();
if (sum >= K){
std::cout << it->first << "\n";
b = false;
break;
}
}
if(b){
std::cout << scoreReverse.begin()->first << "\n";
}
}