The Delivery Dilemma Codeforces Problem code solution -
Petya is preparing for his birthday. He decided that there would bedifferent dishes on the dinner table, numbered from to . Since Petya doesn't like to cook, he wants to order these dishes in restaurants.
Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his orders fromdifferent places. To speed up this process, he wants to order courier delivery at some restaurants. Thus, for each dish, there are two options for Petya how he can get it:
- the dish will be delivered by a courier from the restaurant , in this case the courier will arrive in minutes,
- Petya goes to the restaurant on his own and picks up the dish, he will spend minutes on this.
Each restaurant has its own couriers and they start delivering the order at the moment Petya leaves the house. In other words, all couriers work in parallel. Petya must visit all restaurants in which he has not chosen delivery, he does this consistently.
For example, if Petya wants to orderdishes and , and , then he can order delivery from the first and the fourth restaurant, and go to the second and third on your own. Then the courier of the first restaurant will bring the order in minutes, the courier of the fourth restaurant will bring the order in minutes, and Petya will pick up the remaining dishes in minutes. Thus, in minutes all the dishes will be at Petya's house.
Find the minimum time after which all the dishes can be at Petya's home.
The first line contains one positive integer( ) — the number of test cases. Then test cases follow.
Each test case begins with a line containing one integer( ) — the number of dishes that Petya wants to order.
The second line of each test case containsintegers ( ) — the time of courier delivery of the dish with the number .
The third line of each test case containsintegers ( ) — the time during which Petya will pick up the dish with the number .
The sum ofover all test cases does not exceed .
For each test case output one integer — the minimum time after which all dishes can be at Petya's home.
Sort the array according to the delivery time and iterate over pair of vector.
store sum of pickup time till sum< delivery time .
then print the curr delivery time .
Follow code below-