작성
·
239
0
import sys
#sys.stdin = open("in4.txt","r")
n = int(input())
clist = []
for i in range(n):
temp = int(input())
clist.append(temp)
res = float('inf')
def DFS(v,a,b,c):
global res
if v == n:
if a != b and b != c and c != a:
temp = max(a,b,c) - min(a,b,c)
if temp < res:
res = temp
else:
DFS(v+1,a+clist[v],b,c)
DFS(v+1,a,b+clist[v],c)
DFS(v+1,a,b,c+clist[v])
DFS(0,0,0,0)
print(res)
저는 위와 같이 코드를 짜보았는데 4,5번에서 계속 시간 초과가 납니다. 선생님 코드의 효율이 더 좋은것인지 궁금하고 제가 짠 코드가 논리적으로 맞는지 궁금합니다.