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()))
m = max(h)
ans = 0
for i in range(1,m+2):
    for j in range(n):
        if j == 0:
            if h[0] >= i:
                p = 0
            elif h[0] < i:
                p = 1
        elif j == n-1:
            if p == 0:
                ans += 1
            if p == 1 and h[j] >=i:
                ans += 1
        else:
            if p == 0:
                if h[j] < i:
                    p = 1
                    ans += 1
            if p == 1:
                if h[j] >= i:
                    p = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

t = 0

while len(set(A)) != 1 and max(A) != 0:
    for i in range(n):
        if A[i] != 0:
            break
    B = A[i:]
    for j in range(i, n):
        if A[j] != 0:
            A[j] -= 1
        else:
            break
    t += 1
print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int,input().split()))
N+=1
arr.append(0)
now = 0
min = 100
count = 0
print(arr)

while True:
  min = 100
  if arr[now] == 0:
    now += 1
    if now == N:
      break
  else:
    for i in range(now,N):
      if min > arr[i]:
        if arr[i] == 0:
          last = i
          for j in range(now,i):
            arr[j] = arr[j] - min
          count+=min
          break
        else:
          min = arr[i]
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 14 10:43:31 2020

@author: kiwadanaoki
"""


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

# = max(h)
flag = 0
ans = 0
for i in range(N-1):
   diff =  h[i+1] - h[i]
   if diff > 0:
       if i == 0:
           flag = 1
           flag2 = 1
           
       elif i == N-2:
           ans+=h[i+1]  
           flag2 = 1
           #print(ans)
           
       else:
           flag2 = 1
           
       
           
   elif diff < 0:
       if i == 0:
           flag = -1
           flag2 = -1
           ans+= h[i]
       
       else:
           flag2 = -1   
           
   elif diff == 0:
       if i == 0:
           flag = 0
           flag2 = 0
       else:
           flag2 = 0
           
   if flag > 0 and flag2 < 0 :
       ans += h[i]
       flag = -1
       #print(ans)
   elif flag <0 and flag2 > 0:
       ans -= h[i]
       flag = 1
      # print(ans)
       
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
L = int(sys.stdin.readline().rstrip())
 
if L == 1:
  h = int(sys.stdin.readline().rstrip())
else:
  h = list(map(int, sys.stdin.readline().rstrip().split()))
 
if L == 0:
  ans = 0
elif L == 1:
  ans = h
elif L == 2:
  ans = max(h)
  
else:
  grad1 = h[0] > h[1]
  p= 0
  v= 0
  if grad1:
    p += h[0]
 
  for n in range(2, L):
    grad2 = h[n-1] > h[n] 
    if grad1 == grad2:
      continue
    elif grad2:
      p += h[n-1]
    else:
      v += h[n-1]
    grad1 = grad2
               
  if not grad1:
    p += h[n]
 
  ans = p - v
  print(ans)

Submission status: Wrong Answer

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

maxh = max(h)
count = 0
for i in range(1,maxh+1):
    flag = False
    for j in range(len(h)):
        if flag == False:
            if h[j] >= i and j != len(h)-1:
                flag = True
                continue
            elif j == len(h)-1:
                count += 1
        elif flag == True:
            if h[j] < i:
                flag = False
                count += 1
            elif j == len(h)-1:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
v=sum(l)
e=0
for i in range(max(l)):
  ef=0
  for j in l:
    print(i,j)
    if j>i:
      ef+=1
    else:
      if ef>0:
        e+=ef-1
      ef=0
  if ef>1:
    e+=ef-1
print(v-e)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
ans = 0
if n == 1 and h[0] == 0:
    print(0)
    exit()
while True:
    f = 0
    for i in range(n):
        if f and h[i] == 0:
            break
        if h[i]>0:
            h[i] -= 1
            f = 1
    ans += 1
    if all(x==0 for x in h):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
ans = 0
while True:
    f = 0
    for i in range(n):
        if f and h[i] == 0:
            break
        if h[i]>0:
            h[i] -= 1
            f = 1
    ans += 1
    if all(x==0 for x in h):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def mizuyari(nums):
  minimum=1000
  maximam=-1
  index=-1
  change=False
  for i,j in enumerate(nums):
    if i==0:
      minimum = j
      maximam = j
      continue
    elif i==len(nums)-1:
      if j > maximam:
        maximam = j
      continue
    elif j > maximam:
      maximam = j
    elif nums[i-1] > j and nums[i+1] > j:
      if change==False:
        minimum = j
        index = i
        change=True
      else:
        if minimum > j:
          minimum = j
          index = i
  if index == -1:
    return maximam
  ans = minimum
  for i,j in enumerate(nums):
    j -= minimum
    if j < 0:
      j=0
    nums[i]=j
  ans += mizuyari(nums[:index]) + mizuyari(nums[index + 1:])
  return ans

n=int(input())
lis=list(map(int,input().split()))
ans=mizuyari(lis)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
max = 0

def decrement_garden(cnt):
    prev_value = 0
    tmp_arr = []
    for i in range(len(arr)):
        if arr[i] is not 0:
            arr[i] = arr[i] - 1
            tmp_arr.append(1)
        else:
            tmp_arr.append(0)
    
    for j in range(len(tmp_arr)):
        if j is not 0 and tmp_arr[j] is 0 and tmp_arr[j-1] is not 0 and j < len(tmp_arr) - 1:
            cnt = cnt + 1

    if 1 in tmp_arr:
        return cnt + 1

for i in range(len(arr)):
    if max < arr[i]:
        max = arr[i]
        
for i in range(max):
    cnt = decrement_garden(cnt)

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
flower=[0]*N
count=0
on=0
for j in range(max(h)):
    for i in range(N):
        if i==0:
            on=0
        if on==1 and flower[i]==h[i]:
            count+=1
            on=0
        elif i==N-1:
            count+=1
        if flower[i]<h[i]:
            flower[i]+=1
            on=1
        #print(flower, i, on)
        #print(count)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 #前の花
n_f = 0 #今の花
v = 0 # 谷の数

cnt = min(H)
H -=cnt
precnt = 0
for i in range(max(H)):
    a = 0
    for j in range(N):
        v=0
        if j == 0 and H[j] > 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        a+=v
    print(a)

    for j in range(N):
        if H[j] > 0:
            H[j]-=1
    print(H)
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 #前の花
n_f = 0 #今の花
v = 0 # 谷の数

cnt = min(H)
H -=cnt
for i in range(max(H)):
    for j in range(N):
        v=0
        if N == 0 and H[j] > 0 and H[j+1] == 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        
    for j in range(N):
        if H[j] > 0:
            H[j]-=1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 #前の花
n_f = 0 #今の花
v = 0 # 谷の数

cnt = min(H)
H -=cnt
for i in range(max(H)):
    for j in range(N):
        v=0
        if N == 0 and H[j] > 0 and H[j+1] == 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        
        if H[j] > 0: H[j]-=1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
le = int(input())
ll=list(map(int, input().split(' ')))


res=0

while max(ll)>0:
  i=0
  while i<le:
    if ll[i]==0: 
      i+=1
    else:
      res+=1
      while i<le and ll[i]>0:
        ll[i]-=1
        i+=1

Submission status: Wrong Answer

Solution code:
num = int(input())
flag = "nocheck"
count = 0
num_list = list(map(int,input().split()))
while(1):
  dummy = max(num_list)
  if dummy == 0:
    break
  for i in range(num):
    if num_list[i] == dummy:
      num_list[i] -= 1
      flag = "check"
    else:
      if flag == "check":
        flag = "nocheck"
        break
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
num = int(input())
num_list = list(map(int,input().split()))
num_list.sort(reverse=1)
dummy = 0
for i in range(1,num):
  dummy += num_list[0]-num_list[i]
print(dummy)

Submission status: Wrong Answer

Solution code:
n = int(input())
h_ls = list(map(int, input().split()))
h_ls.insert(0,0)
h_ls.insert(-1,0)

change_count = 0

while True:
    for i in range(n+1):
        status = [0] * 2
        if h_ls[i] == 0:
            status[0] = 'zero'
        else:
            status[0] = 'not_zero'
        if h_ls[i+1] == 0:
            status[1] = 'zero'
        else:
            status[1] = 'not_zero'
        if status[0] != status[1]:
            change_count+= 1
    for i in range(n+2):
        if h_ls[i] != 0:
            h_ls[i] -= 1
    if h_ls == [0] * (n+2):
        break

count = change_count // 2
print(count)

Submission status: Wrong Answer

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

hll = []
cnt = 0

zero_check = []
tmp = []
for h in hl:
    if h != 0:
        tmp.append(h)
    else:
        zero_check.append(tmp)
        tmp = []

if len(tmp) > 0:
    zero_check.append(tmp)

hl = zero_check[:]

while len(hl) > 0:
    for h in hl:
        cnt += 1
        tmp_num = []
        for num in h:
            if num - 1 != 0:
                tmp_num.append(num - 1)
            elif num - 1 == 0 and len(tmp_num) > 0:
                hll.append(tmp_num)
                tmp_num = []
                # cnt += 1
            # print('num:{}, tmp_num:{}, hll:{}, cnt:{}'.format(num, tmp_num, hll, cnt))

        if len(tmp_num) > 0:
            hll.append(tmp_num)

    hl = hll
    hll = []
    # print('hl:{}'.format(hl))

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
count = 0
N = int(input())
h = list(map(int, input().split()))
if max(h) == 0:
    print(count)
count =+ min(h)
h = list(map(lambda x:  x-min(h) ,h))
if max(h) == 0:
    print(count)
h.append(0)
while max(h) != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
print(int(count))

Submission status: Wrong Answer

Solution code:
count = 0
N = int(input())
h = list(map(int, input().split()))
count =+ min(h)
h = list(map(lambda x:  x-min(h) ,h))
if max(h) == 0:
    print(count)
h.append(0)
while max(h) != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
print(int(count))

Submission status: Wrong Answer

Solution code:
count = 0
N = int(input())
h = list(map(int, input().split()))
count =+ min(h)
h = list(map(lambda x:  x-min(h) ,h))
if max(h) == 0:
    print(count)
h.append(0)
while max(h) != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
count = 0
N = int(input())
h = list(map(int, input().split()))
count =+ min(h)
h = list(map(lambda x:  x-min(h) ,h))
if max(h) == 0:
    print(count)
h.append(0)
while max(h) != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
print(count)

Submission status: Wrong Answer

Solution code:
count = 0
# N = int(input())
h = list(map(int, input().split()))
hmin = min(h)
count =+ min(h)
h = list(map(lambda x:  x-hmin ,h))
hmax = max(h)
if hmax == 0:
    print(count)
h.append(0)
hamx = max(h)
while hmax != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
    hmax = max(h)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
count = 0
N = int(input())
h = list(map(int, input().split()))
hmin = min(h)
count =+ min(h)
h = list(map(lambda x:  x-hmin ,h))
hmax = max(h)
if hmax == 0:
    print(count)
h.append(0)
hamx = max(h)
while hmax != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        elif h[i-1] > 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
    hmax = max(h)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
count = 0
# N = int(input())
# h = list(map(int, input().split()))
N = 4
h =[1, 2, 2, 1]
hmin = min(h)
h = list(map(lambda x:  x-hmin ,h))
count =+ min(h)
hmax = max(h)
if hmax == 0:
    print(count)

h.append(0)
hamx = max(h)
while hmax != 0:
    for i in range(len(h)):
        if h[i] <= 0:
            continue
        else:
            for j in range(i+1,len(h)+1):
                if h[j] > 0:
                    continue
                else:
                    count += 1
                    break
    h = list(map(lambda x:  x-1 ,h))
    hmax = max(h)
print(count)

Submission status: Wrong Answer

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

num_ma = h[0]
num_mi = h[0]
ans = 0
flag = True

for i in range(n):
    if h[i] >= num_ma:
        num_ma = h[i]
        flag = True
    else:
        num_mi = h[i]
        ans += num_ma-num_mi
        num_ma = h[i]
        flag = False

ans += min(h)

if flag:
    ans += h[n-1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
hs = [int(i) for i in input().split()]
flag = -1
count = 0

while max(hs) > 0:
    for i in range(n):
        if hs[i] > 0:
            if flag == 1:
                if i == n - 1:
                    flag *= -1
                hs[i] -= 1
            else:
                count += 1
                flag *= -1
                hs[i] -= 1
        else:
            if flag == 1: 
                flag *= -1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(e) for e in input().split()]

array = [[a[j]>i  for j in range(n)] for i in range(max(a))]

print(len([[a for a,b in zip(row,row[1:]+[False]) if a and a!=b]for row in array]))

Submission status: Wrong Answer

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

cnt = 0
while len(h) > 0:
    m = min(h)
    if m > 0:
        h = [h[i]-m for i in range(len(h))]
        cnt += m
    p = h.index(0)
    s,h = h[0:p+1],h[p+1:]
    cnt += max(s)

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
while len(h) > 1:
    m = min(h)
    if m > 0:
        h = [h[i]-m for i in range(len(h))]
        cnt += m
    p = h.index(0)
    s,h = h[0:p],h[p+1:]

    if len(s) > 0:
        cnt += max(s)
if len(h) == 1:
    cnt += h[0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
def dfs(l,r):
  if l==r:
    return h[l]
  if r<l:
    return 0
  res=10**18
  for i in range(l,r+1):
    res=min(res,h[i])
  for i in range(l,r+1):
    h[i]-=res
  for i in range(l,r):
    if h[i]==0:
      return dfs(l,i-1)+dfs(i+1,r)+res
  return 0
print(dfs(0,n-1))

Submission status: Wrong Answer

Solution code:
from collections import deque
q = deque()

n = int(input())
h = list(map(int, input().split()))
for i in h:
    q.append(i)
q.append(0)

ans = 1
c = 0
while sum(q) != 0:
    p = q.popleft()
    if p != 0:
        q.append(p - 1)
        c = 1
    else:
        q.append(0)
        if c == 1:
            ans += 1
            c = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
ans=0
flag=True
f=0
e=N-1
while(flag):
    F=False
    E=False
    for i in range(N):
        if not F:
            if h[i]>0:
                f=i
                F=True
    for i in range(f,N):
        if not E:
            if h[i]==0:
                e=i-1
                E=True

    #print(f)
    #print(e)
    if f>e:
        e=N-1
    for i in range(f,e+1):
        h[i]-=1
    ans+=1
    #print(h)
    flag=False
    for i in range(N):
        if h[i]>0:
            flag=True
print(ans)

Submission status: Wrong Answer

Solution code:
"""
0で断絶が生じなければ、一番低い部分は共通で処理できる

Nもhも小さいので、貪欲？にやればもんだいなさそう。
0以外で連続してる部分それぞれについて、実際に水やりを行う。
伸ばすよりはhを短くする方が処理的に楽
"""




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

ans = 0
while True:
    
    l,r = -1,-1

    for i in range(N):
        if H[i] != 0:
            l = i
            break

    if l == -1:
        break

    for i in range(l,N):
        if H[i] == 0:
            r = i-1
            break

        if i == N-1: r = N-1

    print(l,r)
    tmp =  min(H[l:r+1])
    for i in range(l,r+1):
        H[i] -= tmp
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
"""
0で断絶が生じなければ、一番低い部分は共通で処理できる

Nもhも小さいので、貪欲？にやればもんだいなさそう。
0以外で連続してる部分それぞれについて、実際に水やりを行う。
伸ばすよりはhを短くする方が処理的に楽
"""




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

ans = 0
l,r = 0,0
while True:
    if l > N-1 or r > N-1:
        l,r = 0,0

    while l < N and H[l] == 0:
        l += 1

    if l >= N:
        break

    r = l
    while r < N and H[r] != 0:
        r += 1

    tmp = min(H[l:min(r,N)])
    for i in range(l,min(r,N)):
        H[i] -= tmp
    ans += tmp
    l = r + 1

    

print(ans)

Submission status: Wrong Answer

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

def minus(l,x):
    for i in range(len(l)):
        l[i] = l[i] - x
    

count = 0
count += min(h)
minus(h, min(h))

print(h)
for i in range(N-1):
    if h[i] > h[i+1]:
        count -= h[i+1]-h[i]
        
count += h[-1]
print(count)

Submission status: Wrong Answer

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

if n<=2:
    print(max(h))
else:
    while True:
        count = 1
        for i in range(n-2):
            if h[i]!=0 and h[i+1]==0:
                count += 1
        for i in range(n):
            if h[i]!=0:
                h[i] -= 1
        ans += count
        if all([i==0 for i in h]):
            print(ans)
            exit()

Submission status: Wrong Answer

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

ans = 0

while True:
    count = 1
    for i in range(n-2):
        if h[i]!=0 and h[i+1]==0:
            count += 1
    for i in range(n):
        if h[i]!=0:
            h[i] -= 1
    ans += count
    if all([i==0 for i in h]):
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [0] + [int(a) for a in input().split()]
# for _ in range(N):
#     h.append(int(input()))
answer = 0
for i in range(1, N):
    answer += max(H[i] - H[i-1], 0)

print(answer)

Submission status: Wrong Answer

Solution code:
n= int(input())
h= list(map(int, input().split()))
x=max(h)
ans=0
count=0
for i in range(10009):
    count=0
    if h[-1]==0:
        break
    ans+=1
    for j in range(n):
        if h[j]==0 and count==0:
            continue
        elif h[j]>0:
            count=1
            h[j]-=1
        else:
            break



print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
min=100
a=0
b=0
size=0
for i in range (N):
  if min>h[i]:
    min=h[i]
  if i!=N-1:
    if h[i]>h[i+1]:
      a+=h[i]
      size+=1
  if i!=N-1 and i!=0:
    if h[i]<h[i+1] and (h[i]-h[i-1])*(h[i+1]-h[i])<=0:
      b+=h[i]
  if i==N-1:
    if h[i-1]<h[i]:
      a+=h[i]
      size+=1
print(a-b)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
min=100
a=0
b=0
size=0
for i in range (N):
  if min>h[i]:
    min=h[i]
  if i!=N-1:
    if h[i]>h[i+1]:
      a+=h[i]
      size+=1
  if i!=N-1 and i!=0:
    if h[i]<h[i+1] and (h[i]-h[i-1])*(h[i+1]-h[i])<0:
      b+=h[i]
  if i==N-1:
    if h[i-1]<h[i]:
      a+=h[i]
      size+=1
print(a-b)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
min=100
a=0
size=0
for i in range (N):
  if min>h[i]:
    min=h[i]
  if i!=N-1:
    if h[i]>h[i+1]:
      a+=h[i]
      size+=1
  if i==N-1:
    if h[i-1]<h[i]:
      a+=h[i]
      size+=1
print(a-min*size+min)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
start = 0
start_int = 0
ans = 0
if n <= 2:
    print(max(h))
else:
    for i in range(1,n-1):
        if h[i-1]>h[i] and h[i]<h[i+1]:
            now = h[start:i+1]
            ans += max(now)-start_int
            start = i
            start_int = h[i]
    if h[-2]<=h[-1]:
        ans += h[-1]-start_int
    else:
        ans += h[-2]-start_int
    print(max(max(h),ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
start = 0
start_int = 0
ans = 0
if n <= 2:
    print(max(h))
else:
    for i in range(1,n-1):
        if h[i-1]>h[i] and h[i]<h[i+1]:
            now = h[start:i+1]
            ans += max(now)-start_int
            start = i
            start_int = h[i]
    if h[-2]<=h[-1]:
        ans += h[-1]-start_int
    else:
        ans += h[-2]-start_int
    print(ans)

Submission status: Wrong Answer

Solution code:
count = 0

def rec(l, r):
    global count
    global h
    global s

    print(l, r)
    if l >= r:
        return

    zero = list()
    for i in range(l, r):
        if h[i] == 0:
            zero.append(i)

    if len(zero) > 0:
        for i in zero:
            if not (l, i) in s:
                rec(l, i)
                s.add((l, i))
            if not (i+1, r) in s:
                rec(i+1, r)
                s.add((i+1, r))
    else:
        for i in range(l, r):
            h[i] -= 1
        count += 1
        rec(l, r)

n = int(input())
h = list(map(int, input().split()))
s = set()

rec(0, len(h))
print(count)

Submission status: Wrong Answer

Solution code:
# 間違ってるのを承知で提出
from itertools import zip_longest
n = int(input())
heights = [int(i) for i in input().split()]

mat = []
for h in heights:
    mat.append([1] * h)

cnt = 0
for nums in zip_longest(*mat, fillvalue=0):
    is_all_one = True
    for i in range(n):
        if nums[i] == 0:
            is_all_one = False
            if nums[i-1] == 1:
                cnt += 1
    if is_all_one:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

mizu=0

while True:
    for l in range(n):
        if h[l]!=0:
            break

    for r in range(l,n):
        if h[r]==0:
            r-=1
            break

    mizu+=1
    for i in range(l,r+1):
        h[i] -= 1

    end=True
    for i in range(n):
       if h[i]!=0:
           end=False

    if end:
        break

print(mizu)

Submission status: Wrong Answer

Solution code:
def mizuyari(h,start,end):
    for i in range(start,end):
        h[i] += 1
    return h



input_line = int(input())
flower = list(map(int, input().split()))
height = []
for i in range(input_line):
    height.append(0)

sum = 0
owari = False
while True:
    start = 0
    end = input_line
    for i in range(input_line):
        if flower[i] > height[i]:
            start = i
            break
    for i in range(end-1,start,-1):
        if flower[i] <= height[i]:
            end = i
    mizuyari(height,start,end)
    sum += 1
    for i in range(input_line):
        if flower[i] <= height[i]:
            owari = True
        else:
            owari = False
            break
    if owari:
        break

print(sum)

Submission status: Wrong Answer

Solution code:
def mizuyari(h,start,end):
    for i in range(start,end):
        h[i] += 1
    return h



input_line = int(input())
flower = list(map(int, input().split()))
height = []
for i in range(input_line):
    height.append(0)
print(flower)
print(height)
sum = 0
owari = False
while True:
    start = 0
    end = input_line
    print(height)
    for i in range(input_line):
        if flower[i] > height[i]:
            start = i
            break
    for i in range(end-1,start,-1):
        if flower[i] <= height[i]:
            end = i
    mizuyari(height,start,end)
    sum += 1
    for i in range(input_line):
        if flower[i] <= height[i]:
            owari = True
        else:
            owari = False
            break
    if owari:
        break

print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[int(x) for x in input().split()]
buf=[0 for i in range(n)]

ans=max(h)

kubo=0
flag=False

for i in range(max(h)):
    for j in range(1,n-1):
        if h[j-1] > h[j] and h[j] < i+1 and h[j-1] >= i+1:
            flag=True
        if flag and h[j] < h[j+1]:
            kubo+=1
            flag=False
    flag=False

print(ans+kubo)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    target = [0] * N
    result = 0
    print(target)
    while not height == target:
        print(height)
        end = False
        result += 1
        for i in range(N):
            if not end:
                if height[i] > 0:
                    end = True
                    height[i] -= 1
            else:
                if height[i] > 0:
                    height[i] -= 1
                else:
                    break
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    result = 0
    tmp = 0
    end = False
    while not end:
        print(height, result)
        for i in range(N):
            if i == 0:
                tmp = height[0]
            if max(height) <= 0:
                # print("hi: " + str(height))
                end = True
                break
            if height[i] <= 0:
                if tmp >= 0:
                    result += 1
            else:
                height[i] -= 1
                if i == N - 1:
                    result += 1
            tmp = height[i]

    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[int(i) for i in range(N)]
L.append(0)
ans=0
for i in range(N):
  ans+=max(0,L[i]-L[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
heights = [int(i) for i in input().split()]

# わからない

Submission status: Wrong Answer

Solution code:
N=int(input())
H=list(map(int,input().split(' ')))
ans = 0
for i in range(N-1):
    ans += max(0,H[i+1]-H[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
H=[int(i) for i in input().split()]
ans=0
while any(h>0 for h in H):
  itv=1
  flag=False
  for h in H:
    if h>0:
      flag=True
    if flag and h<=0:
      itv+=1
  if H[-1]<=0:
    itv-=1
  ans+=itv
  H=[h-1 for h in H]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
N = int(input())
h = np.array(list(map(int,input().split())))
count = 0
tmp = deque()
tmp.append(h)
while True:
    st,en = -1,-1
    if len(tmp) == 0:
        break
    count += min(tmp[0])
    tmp[0] -= min(tmp[0])
    if list(tmp[0]) == [0]*len(tmp[0]):
        tmp.popleft()
        continue
    for i in range(len(tmp[0])):
        if st == -1 and tmp[0][i] != 0:
            st = i
        if st != -1 and tmp[0][i] == 0:
            en = i
        if st != -1 and i == len(tmp[0])-1 and tmp[0][i] != 0:
            en = i+1
        if st != -1 and en != -1:
            tmp.append(tmp[0][st:en])
            st,en = -1,-1
    print(tmp)
    tmp.popleft()
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
N = int(input())
h = np.array(list(map(int,input().split())))
count = 0
tmp = deque()
tmp.append(h)
while True:
    st,en = -1,-1
    if len(tmp) == 0:
        break
    count += min(tmp[0])
    tmp[0] -= min(tmp[0])
    if list(tmp[0]) == [0]*len(tmp[0]):
        tmp.popleft()
        continue
    for i in range(len(tmp[0])):
        if st == -1 and tmp[0][i] != 0:
            st = i
        if st != -1 and tmp[0][i] == 0:
            en = i
        if st != -1 and tmp[0][i] == tmp[0][-1] and tmp[0][i] != 0:
            en = i+1
        if st != -1 and en != -1:
            tmp.append(tmp[0][st:en])
            st,en = -1,-1
    tmp.popleft()
print(count)