PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: abhi_inav
Tester: tabr
Editorialist: iceknight1093
DIFFICULTY:
669
PREREQUISITES:
None
PROBLEM:
A sells items in:
- A packet of 2 for X rupees
- A packed of 4 for Y rupees
Chef wants to buy 10 of the item, what’s the minimum cost to do so?
It is known that X \lt Y \leq 2X.
EXPLANATION:
Since Y\leq 2X, it’s never worse to buy one packet of 4 rather than 2 packets of 2.
So, the optimal way to buy 10 items is to buy 4+4+2, i.e, 2 packets of 4 each, and one packet of 2 items.
The cost of doing this is 2Y + X.
TIME COMPLEXITY
\mathcal{O}(1) per test case.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
x, y = map(int, input().split())
print(2*y + x)