https://www.acmicpc.net/problem/3273
this is really simple. We first sort the list in ascending order and if sum>x, we decerement right pointer since it will decrease our value of sum and else, increment left pointer.
import sys
input = sys.stdin.readline
n=int(input())
lst = list(map(int,input().split()))
m= int(input())
lst.sort()
left,right = 0, len(lst)-1
ans =0
while left<right:
sum= lst[left]+lst[right]
if sum==m:
ans +=1
left+=1
right-=1
elif sum>m:
right-=1
else:
left+=1
print(ans)
n time and space