Pursuit solution codeforces
You and your friend Ilya are participating in an individual programming contest consisting of multiple stages. A contestant can get betweenand points, inclusive, for each stage, independently of other contestants.
Points received by contestants in different stages are used for forming overall contest results. Suppose thatstages of the contest are completed. For each contestant, stages with the highest scores are selected, and these scores are added up. This sum is the overall result of the contestant. (Here denotes rounding down to the nearest integer.)
For example, supposestages are completed, and your scores are . First, stages with the highest scores are chosen — for example, all stages except for the -nd and the -th can be chosen. Then your overall result is equal to .
As of now,stages are completed, and you know the points you and Ilya got for these stages. However, it is unknown how many more stages will be held. You wonder what the smallest number of additional stages is, after which your result might become greater than or equal to Ilya’s result, at least in theory. Find this number!
Each test contains multiple test cases. The first line contains the number of test cases( ). Description of the test cases follows.
The first line of each test case contains a single integer( ) — the number of completed stages.
The second line containsintegers ( ) — your points for the completed stages.
The third line containsintegers ( ) — Ilya’s points for the completed stages.
It is guaranteed that the sum ofover all test cases does not exceed .
For each test case print a single integer — the smallest number of additional stages required for your result to be able to become greater than or equal to Ilya’s result.
If your result is already not less than Ilya’s result, print.
5 1 100 0 1 0 100 4 20 30 40 50 100 100 100 100 4 10 20 30 40 100 100 100 100 7 7 59 62 52 27 31 55 33 35 50 98 83 80 64
0 1 3 4 2
In the first test case, you have scoredpoints for the first stage, while Ilya has scored . Thus, your overall result ( ) is already not less than Ilya’s result ( ).
In the second test case, you have scoredpoints for the first stage, while Ilya has scored . A single stage with an opposite result is enough for both your and Ilya’s overall scores to become equal to .
In the third test case, your overall result is, while Ilya’s result is . After three additional stages your result might become equal to , while Ilya’s result might become equal to .
In the fourth test case, your overall result after four additional stages might become equal to, while Ilya’s result might become equal to . Three stages are not enough.