백준 1449번 수리공 항승

DARTZ·2022년 5월 8일
0

알고리즘

목록 보기
44/135
import sys

sys.stdin = open('input.txt', 'rt')
input = sys.stdin.readline
count = 1

N, L = map(int, input().split())

position = list(map(int, input().split()))
position.sort() # 리스트를 오름차순으로 정렬

start = position[0] # 시작 위치 설정
count = 1 # 기본 테이프 1개로 시작

for tape in position[1:]: # 시작 다음 지점부터 검사
    if tape in range(start, start+L): # 주어진 범위내에 있을경우
        continue # 진행

    else: # 주어진 범위를 벗어날 경우 -> 테이프 범위내에 없을경우
        count += 1 # 테이프 1개 증가
        start = tape # 현재로 시작위치 변경

print(count) # 테이프 개수 출력
profile
사람들이 비용을 지불하고 사용할 만큼 가치를 주는 서비스를 만들고 싶습니다.

0개의 댓글