https://www.acmicpc.net/problem/14888
"""
1. 아이디어
2. 시간복잡도
"""
from sys import stdin
input = stdin.readline
n = int(input())
nums = list(map(int, input().split()))
op = list(map(int, input().split())) # 연산자 : +, -, *, /
maximum = -1e9
minimum = 1e9
def btr(depth, total, plus, minus, multiply, divide):
global maximum, minimum
if depth == n: # 최댓값과 최솟값을 갱신해준다.
maximum = max(total, maximum)
minimum = min(total, minimum)
return
if plus:
btr(depth+1, total + nums[depth], plus-1, minus, multiply, divide)
if minus:
btr(depth+1, total - nums[depth], plus, minus-1, multiply, divide)
if multiply:
btr(depth+1, total * nums[depth], plus, minus, multiply-1, divide)
if divide:
btr(depth+1, int(total / nums[depth]), plus, minus, multiply, divide-1)
btr(1, nums[0], op[0], op[1], op[2], op[3])
print(maximum)
print(minimum)
삼성 기출문제