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

drakath's blog

By drakath, history, 5 weeks ago, In English,

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 ?

 
 
 
 
  • Vote: I like it
  • -23
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +19 Vote: I do not like it

You should always link problems you are referring to

»
5 weeks ago, # |
  Vote: I like it +14 Vote: I do not like it

It's because you can't change the order of the three numbers, so the best solution is 6*(7+1)

»
5 weeks ago, # |
  Vote: I like it -11 Vote: I do not like it

Note that you cannot swap integer, so (a+c) it's not possible.

link: https://codeforces.com/problemset/problem/479/A

»
5 weeks ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

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 '*'

»
5 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

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.