문제
파이프 회사의 수리공이 필요한 테이프 개수를 구하라
여분 : 좌우 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)
'⚡️algorithm' 카테고리의 다른 글
[그리디, 파이썬] 백준 11047. 동전 (0) | 2022.05.10 |
---|---|
[그리디] 백준 4796. 캠핑 (0) | 2022.05.09 |
[그리디, 파이썬] 백준 17509. And the Winner Is.. (0) | 2022.05.09 |
[BFS, 파이썬] 백준 2206. 벽 부수고 이동하기 (0) | 2022.05.06 |
[BFS, 파이썬] 백준 3055. 탈출 - hard (0) | 2022.05.06 |