-
22942 데이터 체커 - 스택코테 대비 python/백준 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")
'코테 대비 python > 백준' 카테고리의 다른 글
2583 영역 구하기 bfs (0) 2023.02.27 11279 최대 힙 (1) 2023.02.18 2504 괄호의 값 - 스택 (0) 2023.02.12 10989 수 정렬하기 정렬 잡기술 (0) 2023.02.06 1158 요세푸스 (0) 2023.02.06