efe-T's picture
Upload folder using huggingface_hub
93237a0 verified
|
Raw History Blame Contribute Delete
2.75 kB

1. Mathematical solution

  1. The variables count whole products, so fractional quantities are not allowed. The objective is to maximise 5x+7y over nonnegative integer pairs satisfying both capacities.

  2. First derive a bound that applies to every feasible plan. Multiply the first inequality by 8/5 and the second by 9/5; both multipliers are nonnegative, so the inequality directions stay unchanged.

  3. The left side becomes 5x+7y. The right side is (8×14+9×18)/5=274/5=54.8. Since profit is an integer, every feasible integer plan has profit at most 54.

  4. Now rule out 54. If 5x+7y=54, reduction modulo 5 gives 2y≡4, so y≡2 modulo 5. The second capacity implies y≤6; therefore the only candidate is y=2.

  5. That candidate requires x=8, but then 2x+y=18>14. Profit 54 is impossible. Consequently any feasible plan has profit at most 53.

  6. The plan x=5, y=4 is feasible: 2×5+4=14 and 5+3×4=17≤18. Its profit is 25+28=53, meeting the tightened bound and proving optimality.

  7. For implementation, enumerate y from 0 to 6. At each y, the largest feasible x is the smaller of floor((14−y)/2) and 18−3y; profit increases with x for fixed y.

  8. The verifier will instead enumerate all bounded x,y pairs and filter both constraints. Agreement checks the search, while the weighted bound plus exclusion of 54 explains why no unseen feasible plan can do better.

2. Python implementation

from fractions import Fraction
candidates = []
for y in range(7):
    x = min((14 - y) // 2, 18 - 3 * y)
    if x >= 0:
        assert 2 * x + y <= 14 and x + 3 * y <= 18
        candidates.append((5 * x + 7 * y, x, y))
profit, x, y = max(candidates)
assert Fraction(profit) <= Fraction(274, 5)
result = {"x": x, "y": y, "profit": profit}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))

Code output:

{"profit": 53, "x": 5, "y": 4}

3. Verification by a different method

The optimised one-dimensional search and the full rectangular enumeration produce the same unique plan. The mathematical bound is stronger than a mere test: it limits all feasible real plans to 54.8 and all integer plans to at most 53 after excluding 54.

feasible = []
for x in range(8):
    for y in range(7):
        if 2 * x + y <= 14 and x + 3 * y <= 18:
            feasible.append((5 * x + 7 * y, x, y))
best = max(p for p, _, _ in feasible)
winners = [(x, y) for p, x, y in feasible if p == best]
assert winners == [(5, 4)]
x, y = winners[0]
result = {"x": x, "y": y, "profit": best}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))

Verifier output:

{"profit": 53, "x": 5, "y": 4}

4. Final result

Produce x=5 and y=4 for maximum profit 53.