from itertools import permutations
n = int(input())
nums = list(map(int,input().split()))
plus, minus , mul, div = map(int,input().split())
operations = []
for i in range(plus):
operations.append("+")
for i in range(minus):
operations.append("-")
for i in range(mul):
operations.append("*")
for i in range(div):
operations.append("/")
per = list(permutations(operations,n-1))
mn = 1e9
mx = -1e9
def op(num1, num2, per):
if per =="+":
return num1+num2
elif per == "-":
return num1-num2
elif per == "*":
return num1*num2
elif per == "/":
if num1<0 or num2<0:
num1 = abs(num1)
num2 = abs(num2)
return -(num1//num2)
else:
return num1//num2
for i in range(len(per)):
tot = 0
prev =nums[0]
for j in range(len(per[i])):
tot = op(prev,nums[j+1],per[i][j])
prev = tot
if tot>mx:
mx = tot
if tot<mn:
mn= tot
print(mx)
print(mn)
'알고리즘' 카테고리의 다른 글
경쟁적 전염 (bfs , 우선순위큐) (0) | 2021.06.17 |
---|---|
괄호변환 (구현, 재귀) (0) | 2021.06.17 |
인구이동 (bfs) (0) | 2021.06.17 |
특정거리의 도시 (bfs/dfs) (0) | 2021.06.14 |
가사 검색 (이진탐색/ binarysearch) (0) | 2021.06.14 |