MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / lookup

Function lookup

CPP/SPOJ_ADAFRIEN.cpp:7–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5ll mod = 998244353;
6
7void lookup(){
8 ll n, k;
9 cin>>n>>k;
10 ll sum = 0;
11 string s;
12 ll val;
13 unordered_map<string, ll> mp;
14 for(int i = 0; i < n; i++){
15 cin>>s>>val;
16 sum += val;
17 mp[s] += val;
18 }
19 if(k >= mp.size()){
20 cout<<sum<<endl;
21 return;
22 }
23
24 priority_queue<ll> pq;
25
26 for(auto i: mp) pq.push(i.second);
27
28 ll ans = 0;
29 while(k--){
30 ans += pq.top();
31 pq.pop();
32 }
33 cout<<ans<<endl;
34}
35
36int main(){
37 lookup();

Callers 1

mainFunction · 0.85

Calls 4

topMethod · 0.80
sizeMethod · 0.45
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected