내가 생각한 코드
import sys
sys.stdin = open("input.txt", "rt")
n, m = map(int,input().split())
a= list(map(int,input().split()))
cnt=0
a.sort()
while len(a) != 0:
if len(a) == 1:
a.pop(0)
cnt+=1
break
if a[0] + a[-1] <= m:
a.pop(0)
a.pop()
cnt+=1
else:
a.pop()
cnt+=1
print(cnt)
선생님 코드1
import sys
sys.stdin = open("input.txt", "rt")
n, m = map(int,input().split())
p = list(map(int,input().split()))
cnt=0
p.sort()
while p:
if len(p) == 1:
cnt+=1
break
if p[0] + p[-1] > m:
p.pop()
cnt+=1
else:
p.pop(0)
p.pop()
cnt+=1
print(cnt)
선생님 코드 2 deque
import sys
from collections import deque
sys.stdin = open("input.txt", "rt")
n, m = map(int,input().split())
p = list(map(int,input().split()))
cnt=0
p.sort()
p = deque(p)
while p:
if len(p) == 1:
cnt+=1
break
if p[0] + p[-1] > m:
p.pop()
cnt+=1
else:
p.popleft()
p.pop()
cnt+=1
print(cnt)