[Baekjoon] 14719 ๋น—๋ฌผ python

sorzzzzyยท2021๋…„ 8์›” 4์ผ
0

Baekjoon Algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
12/46
post-thumbnail

๐Ÿท ๋ฌธ์ œ


๐Ÿ’ก ์ฝ”๋“œ

h, w = map(int,input().split())
blocks = list(map(int, input().split()))
h_max = 0

# ๊ฐ€์žฅ ํฐ ๋†’์ด๋ฅผ ๊ฐ€์ง„ ๋ธ”๋Ÿญ์„ ๊ตฌํ•จ
for i in range(len(blocks)):
    if h_max < blocks[i]:
        h_max = blocks[i]
        h_idx = i

# ์˜ค๋ฅธ์ชฝ ๊ตฌ์—ญ
res = 0
val = 0
for i in range(h_idx+1):
    if val < blocks[i]:
        val = blocks[i]
    res += val

# ์™ผ์ชฝ ๊ตฌ์—ญ
val = 0
for i in range(w-1, h_idx, -1):
    if val < blocks[i]:
        val = blocks[i]
    res += val
    
print(res-sum(blocks))

๐Ÿ”‘

profile
Backend Developer

0๊ฐœ์˜ ๋Œ“๊ธ€