์ฝ๋ํธ๋ฆฌ | ์ฝ๋ฉํ ์คํธ ์ค๋น๋ฅผ ์ํ ์๊ณ ๋ฆฌ์ฆ ์ ์
๊ตญ๊ฐ๋ํ๊ฐ ๋ง๋ ์ฝ๋ฉ ๊ณต๋ถ์ ๊ฐ์ด๋๋ถ ์ฝ๋ฉ ์์ด๋ณด๋ถํฐ ๊ฟ์ ์ง์ฅ ์ฝํ ํฉ๊ฒฉ๊น์ง, ๊ตญ๊ฐ๋ํ๊ฐ ์์ ํ ์ปค๋ฆฌํ๋ผ์ผ๋ก ์ค๋นํด๋ณด์ธ์.
www.codetree.ai
import sys
n = int(input())
nums = list(map(int,input().split()))
p,m = [],[]
for n in nums:
if n<0:
m.append(n)
elif n>=0:
p.append(n)
p.sort()
m.sort()
ans = -sys.maxsize
if len(p) >= 3:
ans = max(ans,p[-1] * p[-2] * p[-3])
if len(p) >= 1 and len(m) >= 2:
ans = max(ans,p[-1] * m[0] * m[1])
if len(p) >= 2 and len(m) >= 1:
ans = max(ans,m[-1] * p[0] * p[1])
if len(m) >= 3:
ans = max(ans,m[-1]*m[-2]*m[-3])
print(ans)