🔻PS/Baekjoon
[Baekjoon] 백준 1253 좋다 Python
_니지
2024. 10. 15. 21:25
https://www.acmicpc.net/problem/1253
cnt = 0
N = int(input())
num = list(map(int, input().split(" ")))
num.sort()
cnt = 0
for i in range(N):
target = num[i]
left = 0
right = N-1
while left < right:
if left == i:
left += 1
continue
if right == i:
right -= 1
continue
total = num[left] + num[right]
if total == target:
cnt += 1
break
elif total < target:
left += 1
else:
right -= 1
print(cnt)
728x90
반응형