본문 바로가기
알고리즘/백준

백준-3273번(두 수의 합)-python3

by nyeongha 2023. 11. 26.
import sys

n = int(sys.stdin.readline())
a_list=list(map(int,sys.stdin.readline().split()))
xx = int(sys.stdin.readline())

cnt=0
a_list.sort()


start=0
end=n-1
while start<end:
    t=a_list[start]+a_list[end]
    if t<xx:
        start+=1

    elif t==xx:
        cnt+=1
        end-=1


    elif t>xx:
        end-=1

print(cnt)

'알고리즘 > 백준' 카테고리의 다른 글

백준-4153번(직각삼각형)-python3  (0) 2023.11.26
백준-4101번(크냐?)-python3  (0) 2023.11.26
백준-3184번(양)-python3  (0) 2023.11.26
백준-3053번(택시 기하학)-python3  (0) 2023.11.26
백준-3052번(나머지)-python3  (0) 2023.11.26