[백준] 3649번 로봇 프로젝트

HL·2021년 6월 18일
0

백준

목록 보기
97/104

문제 링크

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

풀이

  • 투포인터

후기

  • 테스트케이스 여러개 처리를 안해줘서 좀 헤맸다

코드

import sys


def solution():
    read = sys.stdin.readline

    while True:
        try:
            x = int(read()) * 10 ** 7
        except:
            break
        n = int(read())
        parts = [int(read()) for _ in range(n)]
        parts.sort()

        if n <= 1:
            print('danger')
            continue

        s = 0
        e = n-1

        while True:
            summ = parts[s] + parts[e]
            if summ == x:
                possible = True
                break
            elif summ < x:
                s += 1
            elif summ > x:
                e -= 1

            if s == e:
                possible = False
                break

        if possible:
            print(f'yes {parts[s]} {parts[e]}')
        else:
            print('danger')


solution()
profile
Swift, iOS 앱 개발을 공부하고 있습니다

0개의 댓글