ADAFRIEN  Ada and Friends
Ada the Ladybug has many friends. They always celebrate something and Ada has to buy them gifts. It is pretty costly so she have decided to unfriend some of them. What is the maximum of money she can spare?
Input
The first line of each testcase will contain two integers 1 ≤ Q K ≤ 10^{5}, the number of celebrations (Q) and the maximum number of friends Ada wants to unfriend (K).
The next Q lines will contain s (the name of friend to whom Ada will buy gift) and 1 ≤ E ≤ 10^{9}+1 (the expenses).
Names will contain at most 40 lowercase english letters.
Output
For each testcase, print the number of money Ada could spare.
Example Input
6 1 uvuvwevwevweonyetenyevweugwemubwemossas 10 ryuk 11 uvuvwevwevweonyetenyevweugwemubwemossas 5 fegla 3 tenshikanade 7 fegla 2
Example Output
15
Example Input
4 3 frodo 1 harrypotter 2 frodo 2 harrypotter 2
Example Output
7
Example Input
7 2 waynebot 7 lhic 4 petr 5 umnik 9 izrak 6 tourist 11 zlobobber 9
Example Output
20
Example Input
6 3 dufresne 5 gump 11 dufresne 3 mcmurphy 19 leon 10 dufresne 1
Example Output
40
hide comments
tarun_28:
20200601 15:07:14
And obviously, using "unordered" map will be more efficient here.


satish18:
20191107 12:06:49
Beware when maximum number of friends Ada wants to unfriend (K) is greater than Ada friends. 

aminetrabelsi:
20190911 01:13:54
there can be 10^5 similar names each can be up to 10^9+1. if you use int you will get wrong answer 

justasle:
20190715 21:09:49
In the problem statement is it not guaranteed that K will always be <= the amount of unique friends. Be careful with this when solving the problem. Also, make sure to use long long instead of int to avoid overflow since the numbers can be quite large. 

harsh_pandey:
20190620 19:52:18
using map and sorting by second of element of map and then deleting k greatest elements from the map. wrong answer on 16 case. please help. 

jodobear:
20190302 16:30:23
Yeah, even i got NZEC in Python. @julkas 

ajaytec227:
20181117 07:46:42
Use 64 bit integer and not 32 bit type


akjol2049:
20181107 20:00:23
waynebot


silverheart:
20181006 23:21:55
@trishala_naman check your code your are accessing a value out of bound of an array that's why u are getting SIGSEGV 

hercules_7:
20180104 19:48:56
@trishala_naman what is the status of Runtime Error? 
Added by:  Morass 
Date:  20171008 
Time limit:  2s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Tunisian Collegiate Training Contest  Round #01 