Festivals
Practice
4.4 (16 votes)
Accessing maps
Data structures
Easy
Hash tables
Implementation
Priority queue
String manipulation
Problem
85% Success 3842 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Alice likes festivals a lot as we all do. He also likes spending money on these festivals. He spends money in buying various things on these festivals. But he has problem of forgetting. He only remembers his top three maximum spendings for any festival.
For eg, on Holi he spends 25 units on colors, 50 units on water sprays, 100 units on gifts, 150 units on sweets but he remebers only his top 3 spendings ,i.e., 50, 100 & 150.
Now as the year ends he wants to know the festival on which he spent most of his money that he can remember.

Input Format

First line contains an integer T, denoting number of test cases.
Second line contains an integer N, denoting number of spendings in a year.
Each of the next N lines contain a string S and an integer X denoting festival name and spending on one of the events of that festival.

Output Format

For each test case, print a single line containing the festival name and its total spending that he remembers.
If there are more than 1 festival with the maximum spending, print the one which has lexiographically smallest name.

Constraints

\(1 \le T \le 100\)

\(1 \le N \le 10^4\)

\(1 \le X \le 10^9\)

\(1 \le |S| \le 10; |S| \; denotes\; string\; length\)

S will consist of lowercase and/or uppercase English aplhabets

 

Hint: Hash Tables
 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
28 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyHash MapsOpen
Points:20
16 votes
Tags:
Data StructuresEasyHash MapsHash Tables
Points:20
368 votes
Tags:
Ad-HocApprovedEasyImplementationReadySorting