all dishes are ready in various cafés and consequently Petya needs to get his orders from n better places. To accelerate this interaction, he needs to arrange messenger conveyance at certain eateries. Subsequently, for each dish, there are two choices for Petya how he can get it: the dish will be conveyed by a dispatch from the café I, for this situation the messenger will show up in man-made intelligence
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
all dishes are ready in various cafés and consequently Petya needs to get his orders from n better places. To accelerate this interaction, he needs to arrange messenger conveyance at certain eateries. Subsequently, for each dish, there are two choices for Petya how he can get it:
the dish will be conveyed by a dispatch from the café I, for this situation the messenger will show up in man-made intelligence minutes,
Petya goes to the eatery I all alone and gets the dish, he will spend bi minutes on this.
Every café has its own dispatches and they begin conveying the request right now Petya goes out. As such, all dispatches work in equal. Petya should visit all cafés in which he has not picked conveyance, he does this reliably.
For instance, assuming Petya needs to arrange n=4 dishes and a=[3,7,4,5], and b=[2,1,2,4], then, at that point, he can arrange conveyance from the first and the fourth eatery, and go to the second and third all alone. Then, at that point, the dispatch of the first eatery will acquire the request quite a while, the messenger of the fourth café will get the request 5 minutes, and Petya will get the leftover dishes in 1+2=3 minutes. Subsequently, in a short time every one of the dishes will be at Petya's home.
Figure out the base time after which every one of the dishes can be at Petya's home.
Input
The primary line contains one certain integer t (1≤t≤2⋅105) — the number of experiments. Then, at that point, t experiments follow.
Each experiment starts with a line containing one integer n (1≤n≤2⋅105) — the number of dishes that Petya needs to arrange.
The second line of each experiment contains n integers a1… an (1≤
The third line of each experiment contains n integers b1… bn (1≤bi≤109) — the time during which Petya will get the dish with the number I.
The amount of n over all experiments doesn't surpass 2⋅105.
Output
For each experiment output one integer — the base time after which everything dishes can be at Petya's home.
Step by step
Solved in 4 steps with 1 images