Alpha Planet has only pineapples and prunes as food. Peter the Patron of Alpha School would like to purchase them to eat for lunch. Peter has a budget of P dollars and knows that pineapples cost A dollars each while prunes cost B dollars each. The vendor has Q_A pineapples and Q_B prunes available.
Peter knows that as he eats more of either food, his satisfaction with that food will decrease (or remain the same). Eventually, he could get so sick of a food that his satisfaction becomes negative. Peter’s satisfaction with the i-th unit of pineapples he consumes is given by S_A_i, similarly for prunes it’s given by S_B_i.
Peter’s total satisfaction is given by the sum of all satisfaction values for food he consumes. Given a budget of P dollars, what is the maximum satisfaction Peter can achieve?
Constraints:
- All values are integers
- 0 ≤ P, A, B ≤ 10,000
- 0 ≤ Q_A, Q_B ≤ 1,000
- -1,000 ≤ S_A_i, S_B_i ≤ 1,000
- S_A_i ≥ S_A_(i+1)
- S_B_i ≥ S_B_(i+1)
Input format:
- Line 1: P
- Line 2: Two space separated integers A, B
- Line 3: Two space separated integers Q_A, Q_B
- Line 4: Q_A space separated integers S_A_i
- Line 5: Q_B space separated integers S_B_i
Output format:
-
Line 1: Peter’s total satisfaction
(Problem credit: Bennett Liu)
No editorial available for this problem.