Блог пользователя drakath

Автор drakath, история, 4 года назад, По-английски

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 ?

  • Проголосовать: нравится
  • -23
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится

You should always link problems you are referring to

»
4 года назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

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

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -8 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

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.