코테 대비 python/백준
22942 데이터 체커 - 스택
ylab
2023. 2. 12. 08:51
https://www.acmicpc.net/problem/22942
22942번: 데이터 체커
데이터가 조건에 맞는다면 YES, 조건에 만족하지 않는다면 NO를 출력한다.
www.acmicpc.net
import sys
input = sys.stdin.readline
n = int(input().rstrip())
circles = []
for i in range(n):
x, r = map(int, input().split())
circles.append((x - r, i, 0))
circles.append((x + r, i, 1))
circles.sort()
stack = []
crds = set()
for crd, i, flag in circles:
if crd in crds:
print("NO")
break
if flag == 0:
stack.append((crd, i))
elif stack[-1][1] != i:
print("NO")
break
else:
crds.add(crd)
stack.pop()
if len(stack) == 0:
print("YES")