Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve in Java or C + + , thank you. : ) Farmer John has N ( 1 N 2 * 1 0 5
Please solve in Java or C thank you. :
Farmer John has patches of grass in a line, where patch i has a level of bacteria that differs by from that
of healthy grass For example, if then patch i has a level of bacteria lower than normal, and would
need exactly additional units of bacteria added to raise it to the point where it is considered healthy.
Farmer John wants to ensure every patch of grass is corrected to have a healthy level of bacteria. Conveniently, he owns two
brands of pesticide that he can spray on his field, one that adds bacteria and one that removes bacteria. When Farmer John
sprays either type of pesticide, he stands in patch the rightmost patch and selects a power level for his sprayer
The sprayer has the most impact on patches near Farmer John, with diminishing effect farther away. If Farmer John chooses the
pesticide that adds bacteria, then units of bacteria will be added to patch units to patch units to patch
and so on Patches dotsN will receive no bacteria, since the sprayer isn't set to a level powerful enough to reach
them. Similarly, if Farmer John chooses the pesticide that removes bacteria, then units of bacteria will be removed from patch
units will be removed from patch and so on Again, patches dotsN will be unaffected.
Find the minimum number of times Farmer John has to apply his sprayer such that every patch of grass has the recommended
value of bacteria for healthy grass. It is guaranteed that the answer is at most
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
INPUT FORMAT input arrives from the terminal stdin:
The first line contains
The second line contains integers the initial bacteria levels of each patch of grass.
OUTPUT FORMAT print output to the terminal stdout:
The minimum number of applications necessary to make every patch of grass have the recommended value of bacteria for
healthy grass.
SAMPLE INPUT:
SAMPLE OUTPUT:
Use the type of pesticide that removes bacteria, at a power level of five times. Then use the type of pesticide that adds
bacteria, with a power level of one time.
SAMPLE INPUT:
SAMPLE OUTPUT:
SCORING:
Inputs : the answer is at most
Inputs :
Inputs : No additional constraints.
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