๋ฌธ์
https://www.acmicpc.net/status?user_id=wnstjd9701&problem_id=14719&from_mine=1
ํ์ด
# ๋ฐฑ์ค 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 ๊น์ง์ด๋ค.
๊ทธ๋ฆฌ๊ณ ํ์ฌ ๋ธ๋ก์ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์ ํ์ํ๋ค.
๊ทธ ์ค์ ๊ฐ์ฅ ํฐ ๊ฐ๋ค์ ๊ฐ์ ธ์์ ๋ ์ค์ ์์ ๋ถ๋ถ์ ์ ์ฅํ๋ค. ์ด ๊ฐ์ด ํ์ฌ ๋ธ๋ก๋ณด๋ค ๋๋ค๋ฉด ํ์ฌ ๋ธ๋ก์ ๋ฌผ์ด ๊ณ ์ผ ์ ์๋ ๊ฒ์ด๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 13335๋ฒ_ํธ๋ญ (0) | 2023.06.29 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 15685๋ฒ_๋๋๊ณค ์ปค๋ธ (0) | 2023.06.26 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 14890๋ฒ_๊ฒฝ์ฌ๋ก (0) | 2023.06.19 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 2477๋ฒ_์ฐธ์ธ๋ฐญ (0) | 2023.06.16 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 3085๋ฒ_์ฌํ ๊ฒ์ (0) | 2023.06.14 |