PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: iceknight1093
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
You have R red gems, B blue gems, G green gems.
Each gem can be sold for three coins, but a bundle of (red + blue + green) gems can be sold for 10 coins.
Find the maximum number of coins you can earn from selling the gems.
EXPLANATION:
Clearly, it’s optimal to use the bundle whenever possible: selling three gems individually gives us 3+3+3 = 9 coins, while selling them in a bundle gives 10 coins, which is larger.
Each bundle requires one gem of every color.
So, the number of bundles we can form is limited by the minimum amount of gems of any color we have.
That is, let M = \min(R, G, B).
Then, we can only make M bundles of gems at best - all other gems need to be sold individually.
There will be (R-M), (G-M), (B-M) gems remaining of each of the colors after making bundles.
So, the answer is
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
r, b, g = map(int, input().split())
mn = min(r, b, g)
print(10*mn + 3*(r + b + g - 3*mn))