반응형
https://www.acmicpc.net/problem/2467
n = int(input())
lst = list(map(int, input().split()))
if lst[0] >= 0: # all elem is positive
print(lst[0], lst[1])
quit()
if lst[-1] <= 0: # all elem is negative
print(lst[-2], lst[-1])
quit()
left, right = 0, n-1
a, b = lst[left], lst[right]
val = abs(a+b)
while left+1 < right:
if lst[left] + lst[right] > 0:
right -= 1
new = abs(lst[left] + lst[right])
if new <= val:
val = new
a, b = lst[left], lst[right]
elif lst[left] + lst[right] < 0:
left += 1
new = abs(lst[left] + lst[right])
if new <= val:
val = new
a, b = lst[left], lst[right]
else: # sum = 0
a, b = lst[left], lst[right]
break
print(a, b)
댓글