๐๏ธ Algorithm/๐ฉ ๋ฐฑ์ค
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 14719๋ฒ_๋น๋ฌผ
Dbswnstjd
2023. 6. 21. 17:24
๋ฌธ์
https://www.acmicpc.net/status?user_id=wnstjd9701&problem_id=14719&from_mine=1
์ฑ์ ํํฉ
www.acmicpc.net
ํ์ด
# ๋ฐฑ์ค 14719๋ฒ ๋ฌธ์ - ๋น๋ฌผ
h, w = map(int, input().split())
world = list(map(int, input().split()))
answer = 0
for i in range(1, w-1):
left_max = max(world[:i])
right_max = max(world[i+1:])
compare = min(left_max, right_max)
if world[i] < compare:
answer += compare - world[i]
print(answer)
๊ฐ์ฅ ์ฒ์๊ณผ ๊ฐ์ฅ ๋ง์ง๋ง์๋ ๋ฌผ์ด ์ฐฐ ์ ์์ผ๋ฏ๋ก ์ธ๋ฑ์ค๋ 1 ๋ถํฐ w-1 ๊น์ง์ด๋ค.
๊ทธ๋ฆฌ๊ณ ํ์ฌ ๋ธ๋ก์ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์ ํ์ํ๋ค.
๊ทธ ์ค์ ๊ฐ์ฅ ํฐ ๊ฐ๋ค์ ๊ฐ์ ธ์์ ๋ ์ค์ ์์ ๋ถ๋ถ์ ์ ์ฅํ๋ค. ์ด ๊ฐ์ด ํ์ฌ ๋ธ๋ก๋ณด๋ค ๋๋ค๋ฉด ํ์ฌ ๋ธ๋ก์ ๋ฌผ์ด ๊ณ ์ผ ์ ์๋ ๊ฒ์ด๋ค.