Problem:


Score : 300 points

Problem Statement

In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0.
You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq  k \leq N), by repeating the following "watering" operation:

Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.

Find the minimum number of watering operations required to satisfy the condition.

Constraints

1 \leq N  \leq 100

0 \leq h_i \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
h_1 h_2 h_3 ...... h_N

Output

Print the minimum number of watering operations required to satisfy the condition.

Sample Input 1

4
1 2 2 1

Sample Output 1

2

The minimum number of watering operations required is 2.
One way to achieve it is:

Perform the operation with (l,r)=(1,3).

Perform the operation with (l,r)=(2,4).

Sample Input 2

5
3 1 2 3 1

Sample Output 2

5

Sample Input 3

8
4 23 75 0 23 96 50 100

Sample Output 3

221



Sample input:
4
1 2 2 1


Sample output:
2

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))

ans=0
while sum(h)>0:
  for i in range(N):
    if i<N-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
  print(h)
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

N = int(input())
H = list(map(int, input().split()))

if N == 1:
    print(H[0])
    exit()

count = 0
now = [0] * N

left = 0
right = N
while True:
    for l in range(left, right):
        if now[l] < H[l]:
            break

    for r in range(l, right):
        if now[r] == H[r]:
            r -= 1
            break

    count += 1
    for i in range(l, r+1):
        now[i] += 1

#    print(now)
    if now == H:
        print(count)
        exit()

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

N = int(input())
H = list(map(int, input().split()))

count = 0
now = [0] * N

left = 0
right = N
while True:
    for l in range(left, right):
        if now[l] < H[l]:
            break

    for r in range(l, right):
        if now[r] == H[r]:
            r -= 1
            break

    count += 1
    for i in range(l, r+1):
        now[i] += 1

#    print(now)
    if now == H:
        print(count)
        exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
H=list(map(int,input().split()))

divf,tmp,mae=[],[H[0]],H[0]
for i in range(1,n):
  tmp.append(H[i])
  if H[i]<mae:
    divf.append(tmp)
    tmp=[]
  mae=H[i]
divf.append(tmp)
  
ans=0
for i,div in enumerate(divf):
  if len(div)>0:
    if i>0:
      ans+=max(div)-divf[i-1][-1]
    else:
      ans+=max(div)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC116 C - Grand Garden
import numpy as np
n = int(input())
h = list(map(int,input().split()))
l = [9]*n
t = 0
x = 0
while max(h) > 0:
    if x != 0:
        for i in range(n):
            h[i] -= 1

    for i in range(n):
        if h[i] > 0:
            l[i] = 1
        else:
            l[i] = 0

    for i in range(n-1):
        if i == 0 and l[0] == 1:
            t += 1
        if l[i+1]-l[i] == 1:
            t += 1
    x += 1
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))

w=0
while 1:
  if w==0 and h[0]>0:
    w+=1
  for i in range(N):
    if h[i]>0:
      h[i]-=1
    if i<N-1 and h[i]==0 and h[i+1]>0:
      w+=1
  #print(h) 
  if sum(h)==0:
    break
print(w)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[0]+list(map(int,input().split()))+[0]

exbi=[]
exsm=[]
for c,d,e in zip(h[0:],h[1:],h[2:]):
  #print(c,d,e)
  if c<d and d>=e:
    exbi.append(d)
  if c>d and d<=e:
    exsm.append(d)   
#print(exbi,exsm)
print(sum(exbi)-sum(exsm))

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[0]+list(map(int,input().split()))+[0]

exbi=[]
exsm=[]
for c,d,e in zip(h[0:],h[1:],h[2:]):
  #print(c,d,e)
  if c<d and d>e:
    exbi.append(d)
  if c>=d and d<=e:
    exsm.append(d)   
#print(exbi,exsm)
print(sum(exbi)-sum(exsm))

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[0]+list(map(int,input().split()))+[0]

exbi=[]
exsm=[]
for c,d,e in zip(h[0:],h[1:],h[2:]):
  #print(c,d,e)
  if c<d and d>e:
    exbi.append(d)
  if c>d and d<e:
    exsm.append(d)   
#print(exbi,exsm)
print(sum(exbi)-sum(exsm))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
h = list(map(int, input().split()))
h = np.array(h)
h_diff = h[1:] - h[:N-1]
count = 0
print(h_diff)
for i in range(N-1):
    count -= min(h_diff[i], 0)
    
print(count + h[N-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(h) for h in input().split()]
valley_indices = [0]
ans = 0
while min(H) != 0:
    H = [h-1 for h in H if h > 0]
    ans += 1
    
for i in range(1,N-1):
    if H[i-1] > H[i] and H[i] < H[i+1]:
        valley_indices.append(i)
valley_indices.append(N-1)

for i in range(len(valley_indices)-1):
    tmp = H[valley_indices[i]:valley_indices[i+1]+1]
    ans += max(tmp) - min(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))

if N==1:
    print(h[0])
    exit()

mi=min(h)
h0=h[0]
c=h0-mi
ans=mi
for i in range(1,N):
    if h0<h[i]:
        c+=h[i]-h0
    elif h0>h[i]:
        ans+=c
        mi = min(h[i:])
        c=h[i]-mi
    h0=h[i]

ans+=c
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))

mi=min(h)
h0=h[0]
c=h0-mi
ans=mi
for i in range(1,N):
    if h0<h[i]:
        c+=h[i]-h0
    elif h0>h[i]:
        ans+=c
        mi = min(h[i:])
        c=h[i]-mi
    h0=h[i]
ans+=c
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h= list(map(int, input().split()))
cnt=0
for i in range(n-1):
    if h[i+1]-h[i]<0:
        print(str(i) + ";"  + str(h[i]) + str(h[i+1]))
        cnt = cnt + h[i]- h[i+1]
cnt += h[n-1]
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    h = [int(i) for i in input().split()]
    ans = 0
    mul = h[1:N].count(0) + 1
    for i in range(max(h)):
        ans += 1 * mul
        z_cnt = 0
        flag = False
        for j in range(N):
            h[j] = (h[j]-1 if h[j] != 0 else h[j]) 
            if h[j] != 0:
                flag = True
            elif j == N-1 and h[j] == 0 and not flag:
                z_cnt -= 1
            elif j != 0 and j != N-1 and h[j] == 0 and flag:
                z_cnt += 1
                flag = False
        mul = z_cnt + 1


    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        if h[i] != 0:
            h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break
    if start == 0:
        break

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    cnt += abs(lst[i]-lst[i+1])
    if lst[i] > lst[i+1]:
        lst[i+1] += abs(lst[i]-lst[i+1])
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
r = 0
while len(list(set(h))) != 1:
    t = 0
    for k in h:
        if k > 0:
            t = 1
        else:
            if t == 1:
                r += 1
            t = -1
    if t == -1:
        r -= 1
    for i, j in enumerate(h):
        if j != 0:
            h[i] -= 1
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))

#水やり回数を判別する関数
def WaterTime(list):
    times=0
    if list[0]!=0:
        times+=1
    for i in range(1,len(list)):
        if list[i]!=0 and list[i-1]==0:
            times+=1
    return times

ans=0
tmp=0
j=0
while max(h) != 0:
    print(h)
    tmp = max(h)
    for i in h:
        if i!=0 and i<tmp:
            tmp=i
    print(tmp,WaterTime(h))
    ans += tmp*WaterTime(h)
    for j in range(n):
        if h[j]!=0:
            h[j] = h[j]-tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(max(h)):
    h.append(0)
    count = 0
    for k in range(N):
        if h[k] != 0 and h[k + 1] == 0:
            count += 1
    ans += count
    print(count, h)
    h = list(map(lambda x: (x - 1, 0)[x == 0], h))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
ans = 0
count = 1
for i in range(max(h)):
    ans += count
    h.append(0)
    h = list(map(lambda x: (x - 1, 0)[x == 0], h))
    for k in range(N):
        temp = 0
        if h[i + 1] - h[i] < 0:
            temp += 1
    count += temp

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
flower=[0]*(N+1)
H=list(map(int,input().split()))
h=deque(H)
h.appendleft(0)
s=0
i=1
while i<=N-1:
    while h[i]<=h[i+1]:
        i+=1
        if i==N:
            s+=h[N]
            break
    if i==N:
            break
    s+=h[i]
    while h[i]>=h[i+1]:
        i+=1
        if i==N:
            break
    if i==N:
            break
    s-=h[i]

print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst = [int(s) for s in input().split()]
ans=0
head=0
while(head<N):
  i=0
  while(True):
  #  print(head,i,lst,ans)
    if head+i==N:
      ans+=1
      break
    if lst[head]==0 :
      if head+1<N and lst[head+1]==0 :
        ans+=1
      head+=1
      break
    if lst[head+i]==0:
      ans+=1
      break
    lst[head+i]-=1
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
h=list(map(int,input().split()))
if len(set(h))==1:
  print(h[0])
  sys.exit()
h.append(1-2)
totl=0
for i in range(1,max(h)+1):
  cnt=1	
  for j in range(n):
    if h[j]<i:
      if i<=h[j+1]:
        cnt+=1
  totl+=cnt
print(totl)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
totl=0
for i in range(1,max(h)+1):
  cnt=1	
  for j in range(1,n-1):
    if h[j]<i:
      if i<=h[j+1]:
        cnt+=1
  totl+=cnt
print(totl)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))

m = max(h)
s = 0
for i in h:
	s += (m - i)
    
print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    ans = 0
    
    for i in range(1,max(h)+1):
        t = [1 if h[k] >= i else 0 for k in range(N)]
        # print(t)
        for j in range(1, len(t)):
            if((j == 0 and t[0] == 1 and t[1] == 0) or (t[j] == 0 and t[j-1] == 1) or (j == (len(t)-1) and t[len(t)-1] == 1)):
                ans += 1
            
    print(ans)


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    ans = 0
    
    for i in range(1,max(h)+1):
        t = [1 if h[k] >= i else 0 for k in range(N)]
        # print(t)
        for j in range(1, len(t)):
            if((t[j] == 0 and t[j-1] == 1) or (j == (len(t)-1) and t[len(t)-1] == 1)):
                ans += 1
            
    print(ans)


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    ans = 0
    
    for i in range(1,max(h)+1):
        t = [1 if h[k] >= i else 0 for k in range(N)]
        # print(t)
        for j in range(1, len(t)):
            if((t[j] == 0 and t[j-1] == 1) or j == (len(t)-1)):
                ans += 1
            
    print(ans)


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    ans = 0
    
    for i in range(max(h)+1):
        t = [1 if h[k] >= i else 0 for k in range(N)]
        # print(t)
        for j in range(1, len(t)):
            if((t[j] == 0 and t[j-1] == 1) or j == (len(t)-1)):
                ans += 1
            
    print(ans-1)


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
inList = [int(s) for s in input().split(" ")]

ans = 0

def calcMizuyari(inList, prevMizu):
    minNum = 101
    minidx = -1
    mizuSum = 0
    for i,x in enumerate(inList):
        if x < minNum:
            minNum = x
            minidx = i
    
    if prevMizu < minNum:
        mizuSum += (minNum-prevMizu)
    else:
        mizuSum = prevMizu
    #print(inList)
    #print(minNum,minidx,mizuSum)
    if(0 < minidx):
        mizuSum1 = calcMizuyari(inList[0:minidx], mizuSum) - prevMizu
    else:
        mizuSum1 = 0
    if(minidx+1 < len(inList)):
        mizuSum2 = calcMizuyari(inList[minidx+1:], mizuSum) - prevMizu
    else:
        mizuSum2 = 0
    #print("ans:"+str(mizuSum+mizuSum1 + mizuSum2))
    return mizuSum + mizuSum1 + mizuSum2

print(calcMizuyari(inList,ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
ans+=min(a)

def minus(x):
    return x-min(a)
a=list(map(minus,a))

for i in range(len(a)-1):
    if a[i+1]<a[i]:
        ans+=a[i]
if a[n-1]>a[n-2]:
    ans+=a[n-1]-a[n-2]
elif a[n-1]==a[n-2]:
    ans+=a[n-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
ans = []
mx = max(h)

for i in range(n):
    ans.append(mx-h[i])

print(sum(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = list(map(int, input().split()))

i = 0
cnt = 0
while i < len(l):
  if l[i] == 0:
    i += 1
    continue
  j = i
  height = l[i]
  while l[j] > height:
    l[k] -= height
    j += 1
  i += 1
  cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
cnt = 0
low = 0
for i in range(N-1):
    if h[i+1] < h[i] and cnt == 0:
        cnt += h[i]
        low = h[i+1]
    elif h[i+1] < h[i]:
        cnt += h[i] - low
        low = h[i+1]
    elif i == N-2:
        cnt += h[i+1] - low

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if i > 0 and i < n-1 and h[i] <= 0 and h[i-1] >= 0:
            count += 1

        elif i == n-1 and h[i] > 0:
            count += 1
        h[i] -= 1
    if max(h) == 0:
        done = True
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = [int(x) for x in input().split(' ')]

c = 0
while len(set(h)) > 1:
    target = max(h)
    second = sorted(set(h))[-2]
    indexes = [i if x == target else -1 for i, x in enumerate(h)]
    exists = []
    for i in indexes:
        if not exists or exists[-1] != (i != -1):
            exists.append(i != -1)
        h[i] = second
    c += exists.count(True) * (target - second)

print(c + set(h).pop())

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))


# 0が入っていないリストに分割する
# [2,0,0,2,3,0] → [2][2,3]
# それぞれから1を引く。
# [2][2,3]　→ [1][1,2]
# このときのリスト数2が水やり回数　カウントアップする
# 各リストに対して同じ処理を行う

def water(currentnum, currentlist): # 既存リストから新規リストを抽出する
  global count

  # (回数,既存リスト長,既存リスト)
  # currentnum = N
  partlist = [] #新規に作成するリスト
  # currentlist = h #今調査しているリスト
  for i in range(currentnum):
    if currentlist[i] != 0:
      partlist.append(currentlist[i]) # 新規のリストに追加
    else: # 0の場合、そのリストは作成終わり
      # 最初から要素ゼロの場合は処理しない
      if len(partlist)==0:
        partlist=[]
      else:    # 要素数がある場合は処理する
        water(len(partlist),partlist)
    
      partlist=[]
  
  newlist=[]
  print("")
  print(partlist)
  if len(partlist)==len(currentlist): # これが水やり
    print(currentlist)
    count = count + 1
    
    for i in range(currentnum):
      newlist.append(currentlist[i]-1)
    water(len(newlist),newlist)
    print(newlist)
    print(count)


count=0
water(N,h)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
h_list = [int(h) for h in input().split()]


h_min = min(h_list)
for i in range(N):
    h_list[i] -= h_min
ans = h_min
if N > 1:
    if h_list[0] > h_list[1]:
        ans += h_list[0]-h_list[1]
        h_list[0] = 0
    if h_list[N-1] > h_list[N-2]:
        ans += h_list[N-1]-h_list[N-2]
        h_list[N-1] = 0
    h_max = max(h_list)
    while h_max > 0:
        n = h_list.index(h_max)
        i = n
        while i <= N-1:
            if i == N-1:
                h_list[i] = 0
                break
            if h_list[i]>0 and h_list[i]>=h_list[i+1]:
                h_list[i] = 0
            else:
                h_list[i] = 0
                break
            i += 1
        h_list[n] = h_max
        j = n
        while j >= 0:
            if j == 0:
                h_list[j] = 0
                break
            if h_list[j]>0 and h_list[j]>=h_list[j-1]:
                h_list[j] = 0
            else:
                h_list[j] = 0
                break
            j -= 1
        h_list[n] = 0
        ans += h_max
        h_max = max(h_list)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h_list = [int(h) for h in input().split()]


h_min = min(h_list)
for i in range(N):
    h_list[i] -= h_min
ans = h_min
if N > 1:
    if h_list[0] > h_list[1]:
        ans += h_list[0]-h_list[1]
        h_list[0] = 0
    if h_list[N-1] > h_list[N-2]:
        ans += h_list[N-1]-h_list[N-2]
        h_list[N-1] = 0
    h_max = max(h_list)
    while h_max > 0:
        n = h_list.index(h_max)
        i = n
        while i <= N-1:
            if i == N-1:
                h_list[i] = 0
                break
            if h_list[i]>0 and h_list[i]>=h_list[i+1]:
                h_list[i] = 0
            else:
                h_list[i] = 0
                break
            i += 1
        h_list[n] = h_max
        j = n
        while j >= 0:
            if j == 0:
                h_list[j] = 0
                break
            if h_list[j]>0 and h_list[j]>=h_list[j-1]:
                h_list[j] = 0
            else:
                h_list[j] = 0
                break
            j -= 1
        h_list[n] = 0
        ans += h_max
        h_max = max(h_list)
    
    print(ans)
else:
    print(h_list[0]-1)

Submission status: Wrong Answer

Solution code:
import bisect


def mizuyari(flowers):
    if flowers == []:
        return 0
    # print(flowers)
    minheight = min(flowers)
    if minheight == 0:
        if max(flowers) == 0:
            return 0
        leftindex = flowers.index(0)
        rightindex = bisect.bisect(flowers, 0.5, leftindex)
        # print("分割"+str(leftindex)+" "+str(rightindex))
        count = mizuyari(flowers[0:leftindex])+mizuyari(flowers[rightindex:])
        return count
    else:
        count = mizuyari([i - minheight for i in flowers]) + minheight
        return count


N = int(input())
h_list = list(map(int, input().split()))

print(mizuyari(h_list))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
h = np.array(list(map(int, input().split())))


def recurse(arr):
    if len(arr) == 0:
        return 0
    if all([e == 0 for e in arr]):
        return 1

    cnt = 0
    while all([e > 0 for e in arr]):
        arr = arr - 1
        cnt += 1

    next = []
    for e in arr:
        if e != 0:
            next.append(e)
        else:
            cnt += recurse(np.array(next))
            next.clear()
    if len(next) > 0:
        cnt += recurse(np.array(next))

    return cnt


print(recurse(h))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
ans = 0
co = 0
for i in range(n):
    if lis[i] != 0:
        cou = i
        while lis[cou] > 0:
            lis[cou] -= 1
            cou += 1
            if cou == n:
                break
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
flowers = list(map(int,input().split(" ")))
ans = 0

def is_clear(l):
    for ele in l:
        if(ele!=0):
            return False
    return True

while(not is_clear(flowers)):
    start = -1
    end = N

    tmp_l = []
    #水やり範囲を決める処理
    for i,flower in enumerate(flowers):
        if(flower!=0):
            tmp_l.append(i)
        else:
            if(len(tmp_l)!=0):
                break


    if(len(tmp_l)>=2):
        water = min(flowers[tmp_l[0]:tmp_l[-1]])
        for i in tmp_l:
            flowers[i] -= water
    else:
        water = flowers[tmp_l[0]]
        flowers[tmp_l[0]] -= water

    ans += water

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_h = list(map(int, input().split()))


ans = 0
now = 0
for i in range(N):
    if lst_h[i] > now:
        ans += now
    now = lst_h[i]


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if h[i] <= h[i + 1]:
        h[i + 1] -= h[i]
        ans += h[i + 1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))

min_h = min(h)
ans = min_h
for i in range(n - 1):
    if h[i] > h[i + 1]:
        ans += h[i] - min_h
if h[n - 1] > h[n - 2]:
    ans += h[n - 1] - h[n - 2]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
s = [i-1 for i in s]
ans = 0
while(sum(s)!=-n):
    s_new=[i.replace("-1","a") for i in map(str,s)]
    print(s_new)
    s_join = ''.join(s_new)
    non = s_join.split("a")
    num = len([x for x in non if x])
    ans += num
    s = [max(i-1,-1) for i in s]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(x) for x in input().split()]
# print(N, H)

ans = 0
while True:
    begin = 0
    end = 0
    for i in range(N):
        if H[i] != 0:
            begin = i
            break
    # print(H, begin, end)
    for i in range(begin, N):
        # print(H[i])
        if H[i] == 0:
            # print('end={}'.format(i - 1))
            end = i - 1
            break
        end = i
    # print(H, begin, end)
    for i in range(begin, end + 1):
        H[i] -= 1
    ans += 1
    if sum(H) == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sm=sum(l)

  c=1
  i=0
  while True:
    if l[i]>0:
      l[i]-=1
      sm-=1

      if i+1==n or l[i+1]==0:
        c+=1

    i+=1
    if i>=n:
      i=0

    if sm==0:
      return c

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sm=sum(l)

  c=1
  i=0
  while True:
    if l[i]>0:
      l[i]-=1
      sm-=1

      if i+1==n or l[i+1]==0:
        c+=1

    if i+1>=n:
      if l[-1]!=0:
        c+=1
      i=0
    else:
      i+=1

    if sm==0:
      return c

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sm=sum(l)

  c=1
  i=0
  while True:
    if l[i]>0:
      l[i]-=1
      sm-=1

      if i+1<n and l[i+1]==0:
        c+=1

    if i+1>=n:
      if l[-1]!=0:
        c+=1
      i=0
    else:
      i+=1

    if sm==0:
      return c

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sm=sum(l)

  c=1
  i=0
  while True:
    if l[i]>0:
      l[i]-=1
      sm-=1

      if i+1<n and l[i+1]==0:
        c+=1

      if sm==0:
        return c

    if i+1>=n:
      if l[-1]!=0:
        c+=1
      i=0
    else:
      i+=1

print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
l.insert(0,0)
def solve(ls,st,n):
	end =st
	for i in range(st,n):
		if ls[i] !=0:
			end +=1
		else:
			break
	for j in range(st,end+1):
		ls[j] -= 1
	return ls

i=1
cnt=0
while max(l) !=0:
	if l[i]==0:
		i +=1
	else:
		solve(l,i,n)
		cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = int(input())
lst = []
lst.append(lst)
cnt = 1
while (True):
  cnt += 1
  if (s % 2 == 0):
    s = int(s / 2)
  else:
    s = int(3*s + 1)
  if (s not in lst):
    lst.append(s)
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
max_num = max(h)

count = 0
for _ in range(max_num):
    bottom = 0
    for index, flower_num in enumerate(h):
        if flower_num <= 0:
            if index == 0 or index == n-1:
                h.pop(index)
                continue
            if h[index-1] > 0:
                bottom += 1
        h[index] -= 1
    count += (bottom+1)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
h = list(map(int, input().split()))
h = np.array(h)
count = 0

for k in range(max(h)):
    j = 0
    for i in range(0,len(h)):
        if h[i]==0 and i!=j:
            h[j:i] = h[j:i] -1
            count = count+1
            j = i + 1
        elif i ==len(h)-1:
            count = count+1
            h[j:]= h[j:]-1
        elif h[i]==0 and i==j:
            j = i+1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))

lmin = [] #極小値のリスト
lmax = [] #極大値のリスト

if N >=3:
    if max(h) != min(h):
        for i in range(1,N-1):
            if (h[i] >= h[i-1]) and (h[i] > h[i+1]):
                lmax.append(h[i])
        
        for k in range(1,N-1):
            if (h[k] <= h[k-1]) and (h[k] < h[k+1]):
                lmin.append(h[k])

        for j in range(N-1):
            if h[j] == h[j+1]:
                j += 1
            elif h[j] > h[j +1]:
                lmax.append(h[j])
                break
            else:
                break

        for j in range(1,N)[::-1]:
            if h[j] == h[j-1]:
                j -= 1
            elif h[j] > h[j -1]:
                lmax.append(h[j])
                break
            else:
                break

        if (len(lmax) == 1) and (len(lmin) == 1):
            ans = max(h)

        else:
            ans = sum(lmax) - sum(lmin)
    else:
        ans = h[0]

if N == 2:
    ans = max(h)

if N == 1:
    ans = h[0]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))

lmin = [] #極小値のリスト
lmax = [] #極大値のリスト

if N >=3:
    for i in range(1,N-1):
        if (h[i] >= h[i-1]) and (h[i] > h[i+1]):
            lmax.append(h[i])
    
    for k in range(1,N-1):
        if (h[k] <= h[k-1]) and (h[k] < h[k+1]):
            lmin.append(h[k])

    for j in range(N-1):
        if h[j] == h[j+1]:
            j += 1
            if j == N-1:
                lmax.append(h[0])
        elif h[j] > h[j +1]:
            lmax.append(h[j])
            break
        else:
            break

    for j in range(1,N)[::-1]:
        if h[j] == h[j-1]:
            j -= 1
            if j == 0:
                lmax.append(h[0])
        elif h[j] > h[j -1]:
            lmax.append(h[j])
            break
        else:
            break
           

    ans = sum(lmax) - sum(lmin)

if N == 2:
    ans = max(h)

if N == 1:
    ans = h[0]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))

def yama(l):
    r=0
    zf=0
    a=[0]*(len(l)+2)
    for i in range(1,len(l)+1):
        a[i]=l[i-1]
    for i in range(0,len(l)+1):
        if a[i]>0 and zf==1:
            r+=1
            zf=0
        else:
            zf=1
ans=0
while yama(l)==0:
    for i in range(n):
        l[i]-=1
        ans+=yama(l)
print(ans)