Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Geeks and Groceries
Easy Accuracy: 56.47% Submissions: 186 Points: 2

Geek went to a grocery shop with a bag in his hand, this can hold at most K products. He wanted to fill his bag with K products. As geek is greedy, he wanted to fill his bag such that he spends a lesser amount. If two products have the same price then geek chooses the lexicographically smaller named product.

Given N products with their prices, help the geek to choose K products.

Input:
1. The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
2. The first line of each test case contains two space-separated integers N and K.
3. Next
N lines contain a string (contains English lower case letters) and an integer separated by a space.

Output: For each test case, print the product names in the order they have chosen.

Constraints:
1. 1 <= T <= 10

2. 1 <= K <= N <= 100000
3. 1 <= product prices <= 100000
4. 1 <= size of prodcut name <= 10


Example:
Input:

2
3 2

maggi 10
pasta 50
noodles 30
3 2
cake 20
butter 30
bread 30

 

Output:
maggi noodles
cake bread

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Geeks and Groceries

Output Window