Four Gate Push
InterviewTime limit1sMemory limit128 MB
Given mineral and gas budgets and per-unit strengths, maximize total strength over non-negative counts of three unit types.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math, Greedy
- Solved
- No attempts yet
Problem
In a real-time strategy game you are preparing a Protoss army built from three unit types: zealots, stalkers, and sentries. Each unit costs a fixed amount of two resources — minerals and gas — and adds a fixed amount of strength to your army.
You may build any non-negative number of each unit. Given how many minerals and how much gas you currently have, together with the strength each unit adds, determine the maximum total army strength you can obtain.
Input
The input consists of several test cases, one per line. Each line contains five integers M, G, Z, S, and E:
- M (): the amount of minerals you have
- G (): the amount of gas you have
- Z (): the strength of one zealot
- S (): the strength of one stalker
- E (): the strength of one sentry
The input ends with a line of five zeros (), which must not be processed.
Output
For each test case, print on its own line the maximum total army strength you can obtain. This value is uniquely determined.