ETC/Algorithm
백준, 수리공 항승, 1449, 파이썬
coding_genie
2024. 9. 10. 23:10
[유형]
그리디
[문제링크]
https://www.acmicpc.net/problem/1449
[요약]
물이 새는 곳의 위치와, 항승이가 가지고 있는 테이프의 길이 L이 주어졌을 때, 항승이가 필요한 테이프의 최소 개수를 구하는 프로그램을 작성하시오.
[문제풀이]
import sys
from collections import Counter
def input():
return sys.stdin.readline().rstrip()
N, L = map(int,input().split())
locations = list(map(int, input().split()))
locations.sort()
start = locations[0] - 0.5
end = start + L
count = 1
for location in locations:
if start < location < end:
continue
else:
count += 1
start = location - 0.5
end = start + L
print(count)