Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Farmer John is growing N ( 1 < = N < = 2 1 0 5 ) plants of asparagus on his farm! However some
Farmer John is growing N
N
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 ttN
containing all integers from
to N
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 FJs 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 T
The first line of each test case consists of an integer N
The second line consists of N
integers hi
hi
denoting the initial height of the i
th plant in inches.
The third line consists of N
integers ai
ai
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
OUTPUT FORMAT pipe stdout:
Output T
lines, the answer to each test case on a different line. If it is not possible, output
Note that the large size of integers involved in this problem may require the use of bit integer data types eg a "long long" in CC
SAMPLE INPUT:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started