동캄의 코딩도장

백준 1449 [수리공 항승] 파이썬 본문

코테/BOJ

백준 1449 [수리공 항승] 파이썬

동 캄 2022. 9. 3. 21:59

https://www.acmicpc.net/problem/1449

 

1449번: 수리공 항승

첫째 줄에 물이 새는 곳의 개수 N과 테이프의 길이 L이 주어진다. 둘째 줄에는 물이 새는 곳의 위치가 주어진다. N과 L은 1,000보다 작거나 같은 자연수이고, 물이 새는 곳의 위치는 1,000보다 작거나

www.acmicpc.net

#백준 1449

N,L=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
s=[]
for i in range(len(lst)-1):
    s.append(lst[i+1]-lst[i])

ans=0
d=0
i=0
while i<(N-1):
    if d+s[i]>(L-1):
        ans+=1
        i+=1
        d=0
    else:
        d+=s[i]
        i+=1

print(ans+1)

 

#백준 1449 다른 풀이

n, l = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
start = s[0]
end = s[0] + l
cnt = 1
for i in range(n):
    if start <= s[i] < end:
        continue
    else:
        start = s[i]
        end = s[i] + l
        cnt += 1
print(cnt)