[SWEA][Python]#1206. View

MEIN_FIGURยท2021๋…„ 8์›” 9์ผ
0

SWEA_๋ฌธ์ œํ’€์ด

๋ชฉ๋ก ๋ณด๊ธฐ
11/21
post-custom-banner

๐Ÿ“Œํ’€์ด


๋‚ด๊ฐ€ ์“ด ํ’€์ด(์„ฑ๊ณต)

for tc in range(1, 11):
    num = int(input())
    buildings = list(map(int, input().split()))
    
    views = 0
    left, right = 0, 0
    for idx in range(2, num-2):
        # ์–‘์ชฝ 2๊ฐœ์˜ ๊ธฐ๋‘ฅ์—์„œ ์ตœ๋Œ€ ๊ฐ’ ์ธก์ •
        left = buildings[idx-1] if buildings[idx-1] > buildings[idx-2] else buildings[idx-2]
        right = buildings[idx+1] if buildings[idx+1] > buildings[idx+2] else buildings[idx+2]
        top = left if left > right else right
        
        #์–‘์ชฝ ๊ธฐ๋‘ฅ์˜ ์ตœ๋Œ€๊ฐ’๋ณด๋‹ค ๋นŒ๋”ฉ์ด ๋” ๋†’์€ ๊ฒฝ์šฐ, view ์ถ”๊ฐ€
        if buildings[idx] > top :
            views += buildings[idx] - top
    print(f'#{tc} {views}')



๐Ÿ“Œํ›„๊ธฐ


min, max๋ฅผ ํ™œ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„์„ ํ•ด๋ณด๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ, ๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์ฝ”๋“œ๊ฐ€ ์‚ด์ง ๊ธธ์–ด์ง„ ๊ฐ์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

profile
Growing Developer
post-custom-banner

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