⚡️algorithm

[그리디] 백준 1449. 수리공항승

남남이루 2022. 5. 9. 14:48

 

문제

파이프 회사의 수리공이 필요한 테이프 개수를 구하라
여분 : 좌우 0.5
테이프의 최소개수
n 물 새는 개수, l 테이프 길이

 

ts 는 테이프가 시작하는 시점

te 는 테이프가 끝나는 시점

import sys
# f=open('.//그리디//input.txt','w')
sys.stdin = open('.//그리디//input.txt')

n,l = map(int,input().split())
pipe = list(map(int, input().split()))
pipe.sort()
tape = 1
ts, te = pipe[0]-0.5, pipe[0]+0.5
# print(ts,te)

for i in range(len(pipe)):
    if i == 0 :
        continue
    if pipe[i]+0.5 - ts <= l:
            te = pipe[i]+0.5
    else:
        ts = pipe[i]-0.5
        tape += 1
print(tape)