Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Farmer John is growing N(1N2105) plants of asparagus on his farm! However some of his plants have genetic differences, so some plants will grow faster

image text in transcribedimage text in transcribed Farmer John is growing N(1N2105) plants of asparagus on his farm! However some of his plants have genetic differences, so some plants will grow faster than others. The initial height of the i th plant is hi inches, and after each day, the i th plant grows by ai inches. FJ likes some of his plants more than others, and he wants some specific plants to be taller than others. He gives you an array of distinct values t1,,tN containing all integers from 0 to N1 and he wants the i th plant to have exactly ti other plants that are taller than it. Find the minimum number of days so that FJ's request is satisfied, or determine that it is impossible. INPUT FORMAT (pipe stdin): The first will consist of an integer T, denoting the number of independent test cases (1T10). The first line of each test case consists of an integer N. The second line consists of N integers hi(1hi109) denoting the initial height of the i th plant in inches. The third line consists of N integers ai(1ai109) denoting the number of inches the i th plant grows each day. The fourth line consists of N distinct integers ti denoting the array that FJ gives you. It is guaranteed that the sum of N over all test cases does not exceed 2105. OUTPUT FORMAT (pipe stdout): Output T lines, the answer to each test case on a different line. If it is not possible, output -1 . Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++. SAMPLE INPUT: 6 1 10 1 0 2 73 810 10 6 8 1 3 9 7 8 1 3 8 10 SAMPLE OUTPUT: 0 3 2 5 1 1 In the first sample input, there are 6 test cases. In the first test case, there is only one plant, so the condition is satisfied on day 0 . In the second test case, we need the first plant to be shorter than the second plant. After day 1, the heights are 15 and 13 . After day 2 , the heights are both 23 . After day 3 , the heights are 31 and 33 , and that's the first day in which the condition is satisfied. The third and fourth test cases are similar to the second. In the fifth test case, both plants start with an initial height of 7 and a growth rate of 8 . So they will always have identical heights, and therefore the condition is never satisfied. In the first sample input, there are 6 test cases. In the first test case, there is only one plant, so the condition is satisfied on day 0 . In the second test case, we need the first plant to be shorter than the second plant. After day 1, the heights are 15 and 13 . After day 2 , the heights are both 23 . After day 3 , the heights are 31 and 33 , and that's the first day in which the condition is satisfied. The third and fourth test cases are similar to the second. In the fifth test case, both plants start with an initial height of 7 and a growth rate of 8 . So they will always have identical heights, and therefore the condition is never satisfied. In the sixth test case, the condition is not satisfied initially and the growth rates are the same. So the condition can never be satisfied

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

More Books

Students also viewed these Databases questions

Question

What is the difference between a paraphrase and a summary?

Answered: 1 week ago

Question

Discuss all branches of science

Answered: 1 week ago

Question

Identify how culture affects appropriate leadership behavior

Answered: 1 week ago