Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 533 |

@akashverma4 | 291 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@shardul08 | 185 |

@Rajpra786 | 181 |

Complete Leaderboard |

Geek** **went to a grocery shop with a bag in his hand, where he found there are two sections of products and he wanted to take **P** products from the first section and **Q** products from the second section. 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 of the first section and **M **products with their prices of the second section, help the geek to choose those products. Print the names of the products in the order they have chosen

**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 four space-separated integers **N**, **M**, **P**, and **Q**.

3. Next **N** lines contain a string (contains English lower case letters) and an integer separated by a space.

4. Next **M** 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 <= P <= N <= 100000

3. 1 <= Q <= M <= 100000

4. 1 <= product prices <= 100000

5. 1 <= size of prodcut name <= 10

**Example:
Input:**

1

3 3 1 2

maggi 10

pasta 50

noodles 30

cake 10

butter 30

bread 30

**Output:**

cake maggi bread

**Explanation: **Geek has to choose one product from the first section and two products from second section. So, he has chosen **cake** from the second section first (even **cake** and **maggi** have same price, a** cake** is lexicographically smaller.) and then he chose **maggi** from the first section and **bread** from the second section ( **bread** is lexicographically smaller than **butter**)

Login to report an issue on this page.

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

Yes
Geeks and Groceries ||

...