728x90
반응형
정렬하고 풀면 쉽다.
N = int(input())
M = int(input())
li = sorted(list(map(int, input().split())))
ans = 0
s, e = 0, len(li)-1
while s != e:
if li[s] + li[e] == M:
ans += 1
e -= 1
elif li[s] + li[e] < M:
s += 1
elif li[s] + li[e] > M:
e -= 1
print(ans)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1964번 오각형, 오각형, 오각형…(python) (0) | 2020.02.04 |
---|---|
백준 알고리즘 1051번 숫자 정사각형(python) (0) | 2020.02.04 |
백준 알고리즘 1932번 정수삼각형(python) (0) | 2020.02.04 |
백준 알고리즘 1931번 회의실배정(python) (0) | 2020.02.04 |
백준 알고리즘 1934번 최소공배수(python) (0) | 2020.02.04 |