-문제: https://www.acmicpc.net/problem/1449

 

-정답풀이: 

시작지점과 그 시작지점에 테이프 길이를 더하면 그 사이의 위치에는 모두 막을 수 있다는 원리다 

 

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

 

-틀린풀이:

i번째 위치랑 i+1번째 위치를 비교해서 테이프 길이보다 짧으면 테이프의 길이를 차이+0.5 만큼 줄이고, 아닌 경우는 갯수를 세는 식으로 생각했는데 11% 돌아가다가 틀렸다 

문제가 무엇인지 생각해봐야할 것 같다

 

+ Recent posts