78 stairs descent contest
InterviewTime limit1sMemory limit1024 MB
Find the maximum total score of a path from step 1 to step N, where opening chest i needs the previous visited step to be at least H_i+B_i tall.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Binary search, Array
- Solved
- No attempts yet
Problem
In the distant future, POSTECH campus kept expanding to fit the growing number of freshmen. As a result, many facilities became far larger than before. In particular, the 78 stairs went through repeated construction and became a huge staircase made of steps. Steps are numbered from 1 to , and the height of step is . Since these are stairs, the heights decrease monotonically with the step number.
Future POSTECH students found the best use for these 78 stairs, and it is the 78 stairs descent contest. A contestant starts at step 1 and keeps moving down to steps with larger numbers until reaching step . Contestants may skip steps, but they cannot move to a step with a smaller number. Every step except step 1 holds one treasure chest. Step has a treasure chest with score and durability . To open the chest on step and earn its score, the height of the step visited just before must be at least .
Your goal is to win the contest by earning the highest score. Given the score and durability of each chest, find the maximum score you can earn.
Input
The first line contains the number of steps ().
The second line contains integers separated by spaces, giving the height of each step (; ).
The third line contains integers separated by spaces, giving the score of the chest on each step ().
The fourth line contains integers separated by spaces, giving the durability of the chest on each step ().
Output
Print the maximum score that can be earned.