구간합 알고리즘
import sys
input=sys.stdin.readline
n, h = map(int, input().split(" "))
down = [0] * h # 석순
up = [0] * h # 종유석
for i in range(n):
end=int(input())-1
if i%2==0: down[end]+=1
else: up[end]+=1
for i in range(h - 2, -1, -1):
down[i] += down[i + 1]
up[i] += up[i + 1]
down.reverse()
result=[]
for j in range(len(down)):
result.append(down[j]+up[j]) # 각 높이마다 장애물 합
mins=min(result)
cnt=result.count(mins)
print(mins,cnt)
'IT > coding study' 카테고리의 다른 글
[acmicpc] 16918. 봄버맨(python) (0) | 2022.06.12 |
---|---|
[acmicpc] 17142. 연구소 3(python) (0) | 2022.03.16 |
[acmicpc] 3190. 뱀 (python) (0) | 2022.03.07 |
[programmers] [3차] n진수 게임 (python) (0) | 2022.01.24 |
[programmers] [3차] 압축 (python) (0) | 2022.01.18 |