PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
One bucket of popcorn costs X, one drink costs Y, and a combo of a drink + popcorn costs Z.
Find the minimum cost of purchasing exactly two buckets of popcorn and three drinks.
EXPLANATION:
There are two options: buy each item individually, or use the combo.
If the items are bought individually, the cost is 2X + 3Y.
If the combo is used, it can be bought only twice (because we want only two buckets of popcorn), which will leave one drink that must be purchased separately.
So, in this case the cost is 2Z + Y.
The final answer is the minimum of both cases, i.e,
\boxed{\min(2X+3Y, 2Z+Y)}
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
x, y, z = map(int, input().split())
print(min(2*x + 3*y, 2*z + y))