반응형
import sys
N = int(sys.stdin.readline())
ary=[]
for i in range(N):
ary.append(int(sys.stdin.readline()))
full = N
cnt = 0
result=[]
def dfs(i,cnt,full,sum):
while True:
if full==2:
if cnt!=0:
sum+=ary[i+1]
else:
sum+=(ary[i]+ary[i+1])
result.append(sum)
break
//4번째일때 해당
else:
if cnt < 2:
cnt+=1
full-=1
sum+=ary[i]
dfs(i+1,cnt,full,sum)
sum-=ary[i]
cnt-=1
full+=1
else:
full-=1
dfs(i+1,0,full,sum)
full+=1
for idx in range(1):
dfs(idx,0,N,0)
print(max(result))
반응형