[백준] 3151번: 합이 0

whitehousechef·2023년 12월 31일
0

https://www.acmicpc.net/problem/3151

initial

n=int(input())
lst=list(map(int,input().split()))
lst.sort()

def binary_search(start):
    hola=[0 for _ in range(n)]
    hola[start]=lst[start]
    for i in range(start+1,n):
        tmp=lst[start]
        hola[i]= tmp+lst[i]
    left,right=start,n-1
    while left<=right:
        mid=left+(right-left)//2
        if hola[mid]+lst[mid]==0:
            print(lst[mid],lst[start],lst[left])
            left+=1
        if hola[mid]+lst[mid]<0:
            left=mid+1
        else:
            right=mid-1
for i in range(n):
    binary_search(i)

0개의 댓글