Bodybuilding
InterviewTime limit1sMemory limit512 MB
Given daily weight gains and minimum weight bounds, find the most routine runs (each losing X kg) that keep his weight above every day's bound.
- Level
Easy3 of 10
- Topics
- Array, Prefix sum
- Solved
- No attempts yet
Problem
Geonpyo likes working out at the gym and has his own exercise routine. Each time he completes the routine, his body weight drops by kg. He can run the routine as many times as he likes in a single day.
Geonpyo prepared a meal plan for the next days ahead of a bodybuilding competition. On day , the plan adds kg to his weight. However, he must not collapse during training, so his final weight on day must be at least kg. If he trains too much or eats too little so that his final weight on some day is less than kg, he collapses on the spot. Geonpyo wants to win the competition, so he wants to run the routine as many times as possible to build the healthiest body he can. Find the maximum number of times he can run the routine without collapsing.
Input
The first line has two integers and . is the number of days left until the competition, and is the weight in kg lost each time the routine is run.
The second line has integers . The -th integer is the lower bound on his final weight on day .
The third line has integers . The -th integer is the weight gained on day .
Output
Print the maximum number of routine runs Geonpyo can complete without collapsing.
If he collapses within days no matter what he does, print -1.
Constraints
- ()