-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14888.py
More file actions
34 lines (25 loc) · 776 Bytes
/
14888.py
File metadata and controls
34 lines (25 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
answer = []
N = int(sys.stdin.readline())
numbers = list(map(int, input().split()))
add, sub, mul, div = map(int, input().split())
answer_min = 1e9
answer_max = -1e9
def dfs(i, res, add, sub, mul, div):
global answer_min, answer_max
if (add+sub+mul+div) == 0:
answer_max = max(res, answer_max)
answer_min = min(res, answer_min)
return
else:
if add:
dfs(i+1, res+numbers[i], add-1, sub, mul, div)
if sub:
dfs(i+1, res-numbers[i], add, sub-1, mul, div)
if mul:
dfs(i+1, res*numbers[i], add, sub, mul-1, div)
if div:
dfs(i+1, int(res/numbers[i]), add, sub, mul, div-1)
dfs(1, numbers[0], add, sub, mul, div)
print(answer_max)
print(answer_min)