File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import sys
2+ from itertools import *
3+
4+ input = sys .stdin .readline
5+
6+ n = int (input ())
7+ a = list (map (int , input ().split ()))
8+
9+ operator_cnt = list (map (int , input ().split ()))
10+
11+ max_value = float ('-inf' )
12+ min_value = float ('inf' )
13+
14+
15+ def bf (value , idx ):
16+ global max_value , min_value
17+ if idx == n :
18+ max_value = max (max_value , value )
19+ min_value = min (min_value , value )
20+ return
21+ if operator_cnt [0 ] > 0 :
22+ operator_cnt [0 ] -= 1
23+ bf (value + a [idx ], idx + 1 )
24+ operator_cnt [0 ] += 1 # 놓친 부분
25+
26+ if operator_cnt [1 ] > 0 :
27+ operator_cnt [1 ] -= 1
28+ bf (value - a [idx ], idx + 1 )
29+ operator_cnt [1 ] += 1
30+
31+ if operator_cnt [2 ] > 0 :
32+ operator_cnt [2 ] -= 1
33+ bf (value * a [idx ], idx + 1 )
34+ operator_cnt [2 ] += 1
35+
36+ if operator_cnt [3 ] > 0 :
37+ operator_cnt [3 ] -= 1
38+ bf (int (value / a [idx ]), idx + 1 ) # 놓친 부분
39+ operator_cnt [3 ] += 1
40+
41+ bf (a [0 ], 1 )
42+ print (max_value )
43+ print (min_value )
You can’t perform that action at this time.
0 commit comments