Contest Strategy
Time limit2sMemory limit1024 MB
Given three chains of subtasks with points and solve times, find the maximum total score achievable within time T when each problem's subtasks must be solved in order.
- Level
Hard10 of 10
- Topics
- Dynamic programming, Divide and conquer, Prefix sum
- Solved
- No attempts yet
Problem
Eunseong failed Day 2 of the 2024 International Olympiad in Informatics. Unwilling to admit his own shortcomings, he convinced himself that he had played badly because of a poor strategy. He wanted to plan better for future contests, so he considered the best strategy in the case where he knows in advance how long each problem takes to solve. But no one can know solving times before a contest, so he had not improved since the olympiad. One night he dreamed that he was taking Day 2 of the 2024 International Olympiad in Informatics again. In the dream, he knew exactly how long each subtask takes to solve. So he decided to find a way to maximize his score, even in the dream.
The contest has 3 problems and a time limit of seconds. The problems are numbered 1, 2, and 3. Each problem has subtasks, numbered 1 to . Eunseong knows that for each and , subtask of problem is worth points and takes seconds to solve. Some subtasks deduct points when solved, so can be negative.
During the seconds of the contest, Eunseong may solve a particular subtask or do nothing. Subtasks form a strict order: to solve subtask of a problem, where , he must have already solved subtask of that same problem. The final score is the sum of the points of all solved subtasks. Find the maximum score Eunseong can get in the contest.
Input
The first line contains and , separated by a space.
The next three lines give the subtask points. For each , line contains , separated by spaces.
The next three lines give the solving times. For each , line contains , separated by spaces.
Output
Print the maximum score Eunseong can get as a single integer.
Constraints
- For each and , .
- For each and , .
- All given numbers are integers.