Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### drakath's blog

By drakath, history, 5 weeks ago, , Good evening/morning to all,

I am new to this cult of competitive programming, been practicing for about a month seriously, I encountered a problem ( mentioned in the title ) which gives 3 numbers and you've got to find an arithmetic of only + and * that produces the largest value. I use Python and here's my logic: a = int(input()) b = int(input()) c = int(input()) if max(a,b,c)==a: print(max(a*b*c,a*(b+c),a+b+c)) elif max(a,b,c)==b: print(max(a*b*c,b*(a+c),a+b+c)) else: print(max(a*b*c,c*(a+b),a+b+c))

when submitted, It got rejected when given the numbers 6,7 and 1. My program gave back 49, while the jury's gave back 48, which makes no sense to me. Some clarification please ?  Comments (12)
 » You should always link problems you are referring to
•  » » You're right, I apologize for that.
 » It's because you can't change the order of the three numbers, so the best solution is 6*(7+1)
•  » » Thanks man
 » Note that you cannot swap integer, so (a+c) it's not possible.
 » 5 weeks ago, # | ← Rev. 2 →   You cannot get 49 because 6 and 1 are not next to each other, so you cannot add them together, I think. Instead you should do 6 * (7 + 1). If you want the solution to problem, then your answer would be max(a*(b + c), c * (a + b)).Edit: Whoops, I was under the impression that you had to use only one of '+' and '*'
•  » » your solution would fail when a = b = c = 1.
•  » » » yeah I just realized I misunderstood the problem
•  » » » No it wouldn't
•  » » » » I replied to Vroom_varun, not you fam.
 » There are only 3 cases to consider, when the answer is $(a * b) + c$, when the answer is $a * (b + c)$, when the answer is $a * b * c$ or when the answer is $a + b + c$. So we can take the max of those. $max((a * b) + c, max(a * (b + c), max(a * b * c, a + b + c)))$ 82351139 Here is my submission.
•  » » Thank you very much for your time