Algorithm/boj

[파이썬] 3649 로봇 프로젝트

takeU 2022. 9. 16. 12:51
반응형
import sys
input = sys.stdin.readline

while True:
    try:
        x, n = int(input().rstrip()) * 10000000, int(input().rstrip())
        li = sorted([int(input().rstrip()) for _ in range(n)])
        left, right, check = 0, n - 1, 1
        while left < right:
            s = li[left] + li[right]
            if s == x:
                print('yes', li[left], li[right])
                check = 0
                break
            elif s < x:
                left += 1
            else:
                right -= 1
        if check:
            print('danger')
    except:
        break

투포인터