forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1244.cpp
More file actions
30 lines (26 loc) · 649 Bytes
/
1244.cpp
File metadata and controls
30 lines (26 loc) · 649 Bytes
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
class Leaderboard
{
public:
Leaderboard() {}
void addScore(int playerId, int score)
{
players.erase({sc[playerId], playerId});
sc[playerId] += score;
players.insert({sc[playerId], playerId});
}
int top(int K)
{
int res = 0;
for (auto it = players.rbegin(); it != players.rend() && K > 0; ++it, --K)
res += it->first;
return res;
}
void reset(int playerId)
{
players.erase({sc[playerId], playerId});
sc.erase(playerId);
}
private:
set<pair<int, int>> players;
unordered_map<int, int> sc;
};