๋์ ์ฝ๋
for t in range(1,11):
n = int(input())
arr = list(map(int,input().split()))
result = 0
for i in range(2,n-2):
mid = arr[i]
left = max(arr[i-1],arr[i-2])
right = max(arr[i+1],arr[i+2])
if mid > left and mid > right :
result += mid - max(left,right)
print("#"+str(t) , result )
์ผ์ชฝ, ์ค๋ฅธ์ชฝ, ๊ฐ๊ฐ ๋น๊ตํ๋๋ฐ
๊ทธ๋ดํ์๊ฐ ์์๋ค
์ด์ฐจํผ ๊ธฐ์ค์ด ์ ์ผ ๋์์ผ๋๋๊น ใ ใ
๋ค๋ฅธ ์ฌ๋ ํ์ด
for T in range(1, 11):
n=int(input())
data=list(map(int, input().split()[:n]))
count=0
for i in range(2, (len(data)-2)):
temp=list(data[i-2:i+3])
if temp[2]==max(temp):
temp.sort(reverse=True)
count+=temp[0]-temp[1]
print(f"#{T} {count}")
5๊ฐ์ ์์๋ฅผ ๊ฐ๋ tmp ๋ฐฐ์ด
์ค์์ธ tmp[2] ๊ฐ ์ ์ผ ํฌ๋ฉด ์กฐ๊ฑด ๋ง์กฑ
๋ง์กฑํ๋ ์ธ๋์ cnt ๋ฅผ ์ฐพ๊ธฐ์ํด ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ ํ sort
์ฐจ ๊ตฌํ๊ธฐ tmp[0] - tmp[1]
'Algorithm > SWEA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SWEA - D3] 1217. ๊ฑฐ๋ญ ์ ๊ณฑ (0) | 2023.04.24 |
---|---|
[SWEA - D3] 4406. ๋ชจ์์ด ๋ณด์ด์ง ์๋ ์ฌ๋ (0) | 2023.04.20 |
[SWEA - D2] 1984. ์ค๊ฐ ํ๊ท ๊ฐ ๊ตฌํ๊ธฐ (0) | 2023.04.18 |
[SWEA - D2] 1204. ์ต๋น์ ๊ตฌํ๊ธฐ (0) | 2023.04.18 |
[SWEA - D2] 1983. ์กฐ๊ต์ ์ฑ์ ๋งค๊ธฐ๊ธฐ (0) | 2023.04.17 |