Pineapple and Prune Purchasing
Practice
0 (0 votes)
Problem
86% Success 558 Attempts 30 Points 1s Time Limit 32MB Memory 1024 KB Max Code

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)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
58 votes
Tags:
AlgorithmsApprovedEasyMathOpen
Points:20
238 votes
Tags:
Binary search treeEasyMapsOpenTrees
Points:50
1 votes
Tags:
Dynamic ProgrammingLinear AlgebraHardMatrix ExponentiationAlgorithmsMathematicsOpenApproved
Editorial

No editorial available for this problem.