#46197: Python 解


chunyutsai97@gmail.com (淳)

School : 臺北市立陽明高級中學
ID : 259744
IP address : [122.116.19.249]
Last Login :
2025-06-15 23:28:58
g595. 1. 修補圍籬 -- 2021年11月APCS | From: [203.64.228.61] | Post Date : 2025-06-04 11:11

n = int(input())
h = list(map(int, input().split()))
a = 0

if h[0] == 0:
    a += h[1]
if h[-1] == 0:
    a += h[-2]
for i in range(1, n-1):
    if h[i] == 0:
        a += min(h[i-1], h[i+1])

print(a)

 
ZeroJudge Forum