Skip to content

Commit 598c97a

Browse files
committed
99차 1번 문제 풀이(참고)
1 parent 46ecf1d commit 598c97a

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

live9/test99/문제1/박희경.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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)

0 commit comments

Comments
 (0)