[백준] 1449. 수리공 항승

원숭2·2022년 1월 17일
0

백준

목록 보기
5/54

문제

풀이

  1. 우선 주어진 값을 정렬.
  2. for문을 돌면서 요소가 length 범위 밖이면, start를 요소로 바꿔주고 결과값에 +1

코드

def repair() :
    n, l = map(int, input().split())
    arr = list(map(int, input().split()))   
    arr.sort()
    count = 1
    start = arr[0]
    
    for a in arr :
        length = start + l - 1
        
        if a <= length :
            continue
        else :
            start = a
            count += 1
        
    print(count)     
repair()

0개의 댓글