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()))

global count
count = 0


def f(l, r, arr):
    # l以上r未満の範囲で探索
    global count
    while len(arr[l:r]) > 0 and all(arr[l:r]) and l < r:
        # l からrまですべて1以上のときはデクリメントし続ける
        arr = [a-1 if l <= idx and idx < r else a for idx, a in enumerate(arr)]
        count += 1
    # ずべてが0だったら終了
    if sum(arr) == 0:
        return
    # l以上r未満のどっかに0が含まれるので、含まれない範囲を抽出
    if arr[0] > 0:
        # 左端がl、以後0が見つかったらr, なかったら右端
        r = arr.index(0) if 0 in arr else len(arr)
        print(arr[0])
        f(0, r, arr)
    elif arr[0] == 0:
        # 左から数えて最初に1以上のインデックスがl、その次の0もしくは右端がr
        a, b = -1, len(arr)
        for idx, x in enumerate(arr):
            if x == 0 and a > 0:
                b = idx
                break
            if x > 0 and a < 0:
                a = idx
        f(a, b, arr)


f(0, n, h)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
listH= list(map(int, input().split()))
minH=min(listH)
indexF=0
while indexF < len(listH):
    listH[indexF]-=minH
    indexF+=1
sum=minH

def getZeroIndex(listH):
    listZeroIndex = []
    index = 0
    while index < len(listH):
        if listH[index] == 0:
            listZeroIndex.append(index)
        index += 1
    return listZeroIndex


def mizuyari(listH, listZeroIndex, sum):
    if not 0 in listZeroIndex:
        index = 0
        nextMin = 100
        while index < listZeroIndex[0]:
            if nextMin > listH[index] and listH[index]!=0:
                nextMin = listH[index]
            index += 1
        index = 0
        sum += nextMin
        while index < listZeroIndex[0]:
            listH[index] -= nextMin
            index += 1

    index2 = 0
    while index2 < len(listZeroIndex)-1:
        nextMin = 100
        index3 = listZeroIndex[index2]+1
        if index3 == listZeroIndex[index2+1]:
            pass
        else:
            while index3 < listZeroIndex[index2+1]:
                if nextMin > listH[index3] and listH[index3]!=0:
                    nextMin = listH[index3]
                index3 += 1
            index3 = listZeroIndex[index2]+1
            sum += nextMin
            while index3 < listZeroIndex[index2+1]:
                listH[index3] -= nextMin
                index3 += 1
        index2 += 1

    if listZeroIndex[len(listZeroIndex)-1] != len(listH)-1:
        index4 = listZeroIndex[len(listZeroIndex)-1]+1
        nextMin = 100
        while index4 < len(listH):
            if listH[index4] < nextMin:
                nextMin = listH[index4]
            index4 += 1
        index4 = listZeroIndex[len(listZeroIndex)-1]+1
        sum += nextMin
        while index4 < len(listH):
            listH[index4] -= nextMin
            index4 += 1
    return listH, sum


index5 = 0
while index5 < 10:
    listZeroIndex = getZeroIndex(listH)
    listH, sum = mizuyari(listH, listZeroIndex, sum)
    if len(listH) == len(listZeroIndex):
        break
    index5 += 1
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
ans = 0
for _ in range(100):
  streak = False
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      if streak:
        pass
      else:
        ans += 1
    else:
      streak = False
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
ans = 0
for _ in range(100):
  streak = False
  for i in range(n):
    if h[i] > 0:
      if streak:
        pass
      else:
        ans += 1
    else:
      streak = False
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
		print(L)
		print(count)
		print(" ")

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			l[i] = l[i] - m
		count += m
		l = " ".join( list(map(str , l)) )
		l = l.split("0")
		for a in l:
			L.append(list(map(int, (a.split()))))
		L.remove(lis)
		while [] in L:
			L.remove([])


print(count)

Submission status: Wrong Answer

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

# Hを1段ずつ減らしていく.
# 値が正の区間 (left, right) が一つ見つかるごとに答えは1増える.

ans = 0
while sum(H) > 0:
    left = right = 0
    prev = -1
    segment = []
    for i, h in enumerate(H):
        if h == 0 and prev != 0:
            right = i
            if left != right:
                segment.append((left, right))
            left = i
        elif h != 0 and prev == 0:
            left = i
        prev = h
    right = i + 1
    segment.append((left, right))
    ans += len(segment)
    #  Hの値が正のところを1段減らす.
    for l, r in segment:
        for i in range(l, r):
            H[i] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
N, *H = map(int, open(0).read().split())
pt = 0
cnt = 0
while pt < N:
    cur = pt
    cnt += 1
    while cur < N and H[cur]:
        H[cur] -= 1
        cur += 1
    while pt < N and H[pt] == 0:
        pt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
res=0
while True:
  res+=1
  i=0;j=0
  for i in range(n):
    if l[i]>0:
      l[i]-=1
      s-=1
      break
  for j in range(i+1,n):
    if l[j]==0:
      break
    else:
      l[j]-=1
      s-=1
  if s==0:
    break
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = [int(i) for i in input().split()]
ans = 0
for i in range(1, 100):
    co = 0
    f = 0
    for j in range(n):
        if f == 1:
            if h[j] < i:
                f = 0
        else:
            if h[j] >= i:
                f = 1
                co += 1
    ans += co
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
res=0
while True:
  res+=1
  i=0;j=0
  for i in range(n):
    if l[i]>0:
      l[i]-=1
      break
  for j in range(i+1,n):
    if l[j]==0:
      break
    else:
      l[j]-=1
  if j==0 and l[i]==0:
    break
print(res)

Submission status: Wrong Answer

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

print(h)

ans = 0

while True:
  given_water = False
  is_continuous = False
  for i in range(N):
    if h[i] > 0:
      if is_continuous is False:
        ans += 1
        is_continuous = True
      h[i] -= 1
      given_water = True
    else: # h[i] == 0
      is_continuous = False
  print(ans)
  print(h)
  if given_water is False:
    break
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
base = max(h)
ans = 0
for i in range(len(h)):
    if  h[i] != base:
       ans += base - h[i]
print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())
a = []
a.append(s)
for i in range(1, 1000000):
    if a[i-1] % 2 == 0:
        a.append(a[i-1]/2)
    else:
        a.append(3*a[i-1]+1)
    for j in range(i-1, -1, -1):
        if a[j] == a[i]:
            print(int(i+1))
            exit()

Submission status: Wrong Answer

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

initial_gr_list = [h]

num = 0
def func(gr_list):
    global num
    n_gr_list = [] # 仕切り後のgr listの箱
    n2_gr_list = [] # 再帰的に次やる予定のgr listの箱
    
    num_ima = int(num) # 今のステップ数をメモっておく。
    
    # 1. まず仕切りごとにgrに分ける。
    for gr in gr_list:
        if gr == []:
            pass
        else:  
            n_gr = []
            #print(gr)
            for i, x in enumerate(gr):
                #print(n_gr)
                if x == 0:
                    n_gr_list.append(n_gr) # 0は仕切り。ここまででgrのlistに追加。
                    n_gr = [] # ここからあたらしいgrが始まる。
                elif i == len(gr)-1: # grの最後のとき。
                    n_gr.append(x)  # 今これはゼロじゃない。n_rgにしまう。
                    n_gr_list.append(n_gr)  # n_grをgr listに追加。
                    n_gr = [] # たぶんいらないけど、一応初期化
                else:
                    n_gr.append(x) # 仕切りでも最後でもないときはn_grにしまう。
    #print('n_gr_list')
    #print(n_gr_list)
    
    # 2. 仕切りごとにminとる
    for n_gr in n_gr_list:
        if n_gr ==[]:
            pass
        else:
            gm = min(n_gr)
            num += gm  # ステップ数を足す。
            n2_gr = [max(x - gm, 0) for x in n_gr]
            n2_gr_list.append(n2_gr)
            #print('n2_gr')
            #print(n2_gr)
    #print('n2_gr_list')
    #print(n2_gr_list)

    if sum(sum(x) for x in n2_gr_list) == 0: # 要素が全部ゼロならおわり。
        return
    else:
        func(n2_gr_list) #再帰的にやる。


print(num)

Submission status: Wrong Answer

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

initial_gr_list = [h]

num = 0
def func(gr_list):
    global num
    n_gr_list = [] # 仕切り後のgr listの箱
    n2_gr_list = [] # 再帰的に次やる予定のgr listの箱
    
    num_ima = int(num) # 今のステップ数をメモっておく。
    
    # 1. まず仕切りごとにgrに分ける。
    for gr in gr_list:
        if gr == []:
            pass
        else:  
            n_gr = []
            #print(gr)
            for i, x in enumerate(gr):
                #print(n_gr)
                if x == 0:
                    n_gr_list.append(n_gr) # 0は仕切り。ここまででgrのlistに追加。
                    n_gr = [] # ここからあたらしいgrが始まる。
                elif i == len(gr)-1: # grの最後のとき。
                    n_gr.append(x)  # 今これはゼロじゃない。n_rgにしまう。
                    n_gr_list.append(n_gr)  # n_grをgr listに追加。
                    n_gr = [] # たぶんいらないけど、一応初期化
                else:
                    n_gr.append(x) # 仕切りでも最後でもないときはn_grにしまう。
    print('n_gr_list')
    print(n_gr_list)
    
    # 2. 仕切りごとにminとる
    for n_gr in n_gr_list:
        if n_gr ==[]:
            pass
        else:
            gm = min(n_gr)
            num += gm  # ステップ数を足す。
            n2_gr = [max(x - gm, 0) for x in n_gr]
            n2_gr_list.append(n2_gr)
            print('n2_gr')
            print(n2_gr)
    print('n2_gr_list')
    print(n2_gr_list)

    if sum(sum(x) for x in n2_gr_list) == 0: # 要素が全部ゼロならおわり。
        return
    else:
        func(n2_gr_list) #再帰的にやる。

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = list(map(int, input().split()))
cnt = 0
def foo(h):
  return min(h - 1, 0)

def idx(l):
  return [i for i, _x in enumerate(l) if _x == 0]

def rm(l):
  if 0 in l:
    l.remove(0)
  if (N-1) in l:
    l.remove(N-1)

while(sum(H)!=0):
  cnt += 1
  zero_i = idx(H)
  rm(H)
  zero_i.insert(0, 0)
  zero_i.append(N)
  for k in range(len(zero_i)-1):
    H[zero_i[k]:zero_i[k+1]] = list(map(foo, H[zero_i[k]:zero_i[k+1]]))
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

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

i = 0
min_h = h.min()
h -= min_h
ans = min_h

if np.all(h==0):
    print(h)
    quit()

split_h = []
zero_index = my_index(h, 0)

split_h = []
list_h = []
for elem in h:
    if elem != 0:
        list_h.append(elem)
    else:
        if list_h:
            split_h.append(np.array(list_h))
            list_h = []

if list_h:
    split_h.append(np.array(list_h))
    list_h = []

while len(split_h):
    sph = split_h.pop()

    min_h = sph.min()
    sph -= min_h
    ans += min_h

    if np.all(sph == 0):
        continue

    for elem in sph:
        if elem != 0:
            list_h.append(elem)
        else:
            if list_h:
                split_h.append(np.array(list_h))
                list_h = []
    if list_h:
        split_h.append(np.array(list_h))
        list_h = []

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(str, input().split()))
counter = 0
leng = 1

while 1:
    h_str = "." + ".".join(h) + "."

    h2 = list(map(str, h_str.split(".0.")))
    print(h2)

    t = 0
    for j in range(len(h2)):
        if h2[t].count(".") != 0:
            h2[t] = h2[t].replace(".", "")
        if h2[t] == "":
            del h2[t]
            continue
        t += 1
    print(h2)
    leng = len(h2)

    for i in range(N):
        if h[i] != "0":
            h[i] = str(int(h[i]) - 1)
        
        else:
            h[i] = "0"
    
    counter += leng
    print(h)
    print(counter)


    if h == ["0"]*N:
        break

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())

H = list(map(int,input().split()))
H.append(min(H))
ans = 0
#mi = min(H)
#for i in range(N+1) :
#    H[i] -= mi
#ans += mi
a = H[0]
for i in range(N) :
    a = H[i]
    #if a == 0 :
    #    continue
    for j in range(i,N+1) :
        
        if H[j] == 0 :
            ans += a*2
            break
        if a <= H[j] :
            H[j] -= a
        else :
            ans += a-H[j]
            a = H[j]
            break
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = list(map(int, input().split()))
cnt = 0
def foo(h):
  return min(h - 1, 0)

def idx(l):
  return [i for i, _x in enumerate(l) if _x == 0]

def rm(l):
  if 0 in l:
    l.remove(0)
  if (N-1) in l:
    l.remove(N-1)

while(sum(H)!=0):
  zero_i = idx(H)
  rm(H)
  zero_i.insert(0, 0)
  zero_i.append(N)
  for k in range(len(zero_i)-1):
    H[zero_i[k]:zero_i[k+1]] = map(foo, H[zero_i[k]:zero_i[k+1]])
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

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

i = 0
min_h = h.min()
h -= min_h
ans = min_h

if np.all(h==0):
    print(h)
    quit()

split_h = []
zero_index = my_index(h, 0)

split_h = []
list_h = []
for elem in h:
    if elem != 0:
        list_h.append(elem)
    else:
        if list_h:
            split_h.append(np.array(list_h))
            list_h = []

while len(split_h):
    sph = split_h.pop()

    min_h = sph.min()
    sph -= min_h
    ans += min_h

    if np.all(sph == 0):
        continue

    for elem in sph:
        if elem != 0:
            list_h.append(elem)
        else:
            if list_h:
                split_h.append(np.array(list_h))
                list_h = []

print(ans)

Submission status: Wrong Answer

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

while True:
    if sum(h) == 0:
        print(count)
        break
    A = []
    j = 0
    for i in range(n):
        A.append(h[i])
        if h[i] == 0:
            count += max(A)
            A = []
        else:
            h[i] -= 1
    if not A:
      A = [0]
    count += min(A)
    if min(A) != 1:
        for i in range(j + 1, n):
            if h[i] == min(A):
                h[i] = 0

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
hs = list(map(int,input().split()))
count = 0
kihuku = [0]
hs = [0]+hs+[0]
count = 0
koubai = None

for h_b,h_a in zip(hs,hs[1:]):
    if koubai is None:
        koubai = (h_a - h_b > 0)
    elif koubai and h_b > h_a:
        kihuku.append(h_b)
        koubai = False
    elif not koubai and h_b<h_a:
        koubai=True
        kihuku.append(h_b)

for k_1,k_2 in zip(kihuku[::2],kihuku[1::2]):
    count+=k_2-k_1
print(count)

Submission status: Wrong Answer

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

l = [0]
cnt=0
sum=0

for i in range(n-1):
    if h[i]<=h[i+1]:
        l[cnt]=(i+1)
    else:
        l.append(i+1)
        cnt+=1
if h[n-1]<h[n-2]:
    l.remove(n-1)
#print(l)

for i in range(len(l)-1):
#    s = h[l[i],l[i+1]]
    mi =  h[l[i]]
#    print(h[l[i]])
    for j in range(l[i],l[i+1]):
        if mi > h[j]:
            mi=h[j]
#            print(mi)
    sum+=h[l[i]]-mi

print(sum+h[l[len(l)-1]])

Submission status: Wrong Answer

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

def dfs(L):
    for i,l in enumerate(L):
        if l != 0:
            break
    L = L[i:N]
    s = 0
    res = 0
    for i,l in enumerate(L):
        print(i,s)
        if l == 0:
            L_ = [l_-1 for l_ in L[s:i]]
            s = i+1
            if len(L_) != 0:
                res += 1
                res += dfs(L_)
        elif i == len(L)-1:
            L_ = [l_-1 for l_ in L[s:len(L)]]
            s = i+1
            if len(L_) != 0:
                res += 1
                res += dfs(L_)
    return res

if sum(h) == 0:
    print(0)
else:
    print(dfs(h))

Submission status: Wrong Answer

Solution code:
def water(list_a):
    if list_a == [0] * len(list_a):
        return 0
    
    elif 0 in list_a:
        n = list_a.index(0)
        return water(list_a[:n]) + water(list_a[n+1:])

    else:
        mini = min(list_a)
        for i in range(len(list_a)):
            list_a[i] -= mini
        return water(list_a) + mini

n = int(input())
list_h = list(map(int, input().split()))
print(list_h)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
h = list(map(int, input().split()))
diff = np.array([i for i in h])


# 右から見ていったときに、最小値までの数値と、それ以降昇順になっている値までに最小値を足す
# 以降それを繰り返す
def find_min_idx(l):
    # 0以外で最小の値を取得
    non_0_list = [i for i in l if i != 0]
    min_value = min(non_0_list)
    min_idx = np.where(l == min_value)[0][0]
    print('---', min_value, min_idx)
    return min_idx


def get_min_value(l, min_idx):
    return l[min_idx]


def get_end_idx(l, min_idx, min_value):
    for idx, i in enumerate(l):
        if idx > min_idx:
            if i == 0:
                return idx - 1
            if i < min_value or i == 0:
                return idx - 1
    else:
        return len(l) - 1


def find_start_idx(l, min_idx):
    if len(l[:min_idx]) == 0:
        return 0
    for idx, i in enumerate(reversed(l[:min_idx])):
        if i == 0:
            return idx
    else:
        return len(l[:min_idx])-1


count = 0
while not all([i == 0 for i in diff]):
    print(count, diff)
    #  import pdb
    #  pdb.set_trace()
    min_idx = find_min_idx(diff)
    min_value = get_min_value(diff, min_idx)
    end_idx = get_end_idx(diff, min_idx, min_value)
    start_idx = find_start_idx(diff, min_idx)
    print('min_idx, end_idx, start_idx', min_idx, end_idx, start_idx)
    #  import pdb
    #  pdb.set_trace()
    for idx, i in enumerate(diff):
        if i == 0:
            continue

        if idx <= end_idx:
            if idx >= min_idx - start_idx - 1:
                diff[idx] -= min_value
            elif idx >= min_idx:
                diff[idx] -= min_value

    count += min_value

    print(count, diff, '\n')

print(count)

Submission status: Wrong Answer

Solution code:
def water(list_a):
    if list_a == [0] * len(list_a):
        return 0
    
    elif 0 in list_a:
        n = list_a.index(0)
        return water(list_a[:n]) + water(list_a[n+1:])

    else:
        mini = min(list_a)
        for i in range(len(list_a)):
            list_a[i] += mini
        return water(list_a) + mini

n = int(input())
list_h = list(map(int, input().split()))
print(list_h)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = input().split(" ")
h = [int(i) for i in h]
print(max(h))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
hi = [int(h) for h in input().split()]

def divide(l):
    div = []
    d = []
    for h in l:
        if (h == 0):
            div.append(d)
            d = []
        else:
            d.append(h)
    div.append(d)
    return div

def watering(l, n):
    div = divide(l)
    cnt = n
    for d in div:
        if not d:
            continue
        else:
            watered = [i - 1 for i in d]
            cnt += 1
            if (len([i for i in watered if i != 0]) == 0):
                break
            cnt = watering(watered, cnt)
    return cnt
    

print(watering(hi, 0))

Submission status: Wrong Answer

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

def dfs(L):
    for i,l in enumerate(L):
        if l != 0:
            break
    L = L[i:N]
    s = 0
    res = 0
    for i,l in enumerate(L):
        if l == 0:
            L_ = [l_-1 for l_ in L[s:i]]
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
        elif i == len(L)-1:
            L_ = [l_-1 for l_ in L[s:len(L)]]
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
    return res

if sum(h) == 0:
    print(0)
else:
    print(dfs(h))

Submission status: Wrong Answer

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

def dfs(L):
    for i,l in enumerate(L):
        if l != 0:
            break
    L = L[i:N]
    s = 0
    res = 0
    for i,l in enumerate(L):
        if l == 0:
            L_ = [l_-1 for l_ in L[s:i]]
            print(s,i,L_)
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
        elif i == len(L)-1:
            L_ = [l_-1 for l_ in L[s:len(L)]]
            print(s,i,L_)
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
    return res

if sum(h) == 0:
    print(0)
else:
    print(dfs(h))

Submission status: Wrong Answer

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

pre = 0
high = []
low = []
for i in range(len(h) - 1):
    if h[i] <= h[i + 1]:
        continue
    else:
        h = h[i:-1]
        break
        
for i in range(len(h) - 1):
    if h[len(h) - i - 1] <= h[len(h) - i - 2]:
        continue
    else:
        h = h[0:n - i + 1]
        break
        
pre = -1
high.append(h[0])
high.append(h[-1])
for i in range(len(h) - 1):
    if h[i + 1] < h[i] and pre == 1:
        high.append(h[i])
        pre = -1
    elif h[i + 1] > h[i] and pre == -1:
        low.append(h[i])
        pre = 1

print(sum(high) - sum(low))

Submission status: Wrong Answer

Solution code:
N = int(input())

H = list(map(int,input().split()))
H.append(min(H))
ans = 0
#mi = min(H)
#for i in range(N+1) :
#    H[i] -= mi
#ans += mi

for i in range(N) :
    a = H[i]
    
    for j in range(i,N+1) :
        if a == min(H[i:]) : ans += a
        if a <= H[j] :
            H[j] -= a
        else :
            ans += a-H[j]
            a = H[j]
            break
    #print(H)
    #print(ans)
print(ans)
#print(H)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

for i in h:
  if i > max:
    max = i

for i in h:
  res += max-i

print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
hl=list(map(int,input().split()))
c=0
mi=min(hl)
c+=mi
if mi!=0:
  for i in range(len(hl)):
    hl[i]-=mi
hl.append(0)
for x in range(100):
  a=101
  for i in range(len(hl)):
    if hl[i]!=0 and a>hl[i]:
      a=i
    if hl[i]==0 and a<i:
      mi2=min(hl[a:i])
      c+=mi2
      for j in range(a,i):
        hl[j]-=mi2
print(c)

Submission status: Wrong Answer

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

def dfs(L):
    for i,l in enumerate(L):
        if l != 0:
            break
    L = L[i:N]
    s = 0
    res = 0
    for i,l in enumerate(L):
        if l == 0:
            L_ = [l_-1 for l_ in L[s:i]]
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
        elif i == len(L)-1:
            L_ = [l_-1 for l_ in L[s:len(L)]]
            res += 1
            s = i+1
            if sum(L_) != 0:
                res += dfs(L_)
    return res

print(dfs(h))

Submission status: Wrong Answer

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

mizuyari = 0
for i in range(int(sorted(h)[n-1])):
    maenohana = False
    for j in range(n):
        if not maenohana and i+1<=int(h[j]):
            mizuyari += 1
        maenohana = i+1<=int(h[j])
print(mizuyari)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
hlist = np.array([_ for _ in map(int,input().split())])

max = np.max(hlist)
min = np.min(hlist)
L = len(hlist)

newlist = np.zeros_like(hlist)
num = 0

list = []



for i in range(max+1):
    over = np.sum(hlist >= i)
    if over == L:
        continue
    num += over
print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
hlist = np.array([_ for _ in map(int,input().split())])

max = np.max(hlist)
min = np.min(hlist)
L = len(hlist)

newlist = np.zeros_like(hlist)
num = 0

list = []



for i in range(max+1):
    over = np.sum(hlist >= i)
    print(over)
    if over == L:
        continue
    num += over

print("ans",num)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=[int(i) for i in input().split()]
k=0
ans=0

while k==0:
    for i in range(n):
        if i==n-1:
            ans+=1
        elif h[i]==0 and i!=0 and h[i-1]!=0:
            ans+=1
    for i in range(n):
        if h[i]!=0:
            h[i]-=1

    if sum(h)==0:
        k=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

H = list(map(int,input().split()))
H.append(min(H))
ans = 0
mi = min(H)
for i in range(N+1) :
    H[i] -= mi
ans += mi

for i in range(N) :
    a = H[i]
    
    for j in range(i,N+1) :
        if a <= H[j] :
            H[j] -= a
        else :
            ans += a-H[j]
            a = H[j]
            break
    #print(H)
    #print(ans)
print(ans)
#print(H)

Submission status: Wrong Answer

Solution code:
from numpy import array,zeros,where
input()
h = array([x for x in input().split()],dtype=int)
x = zeros(len(h),dtype=int)
s = h-x
while False in (h == s):
  idx = where(s == s.max())
  s[idx[0]:idx[-1]-1] += 1
  s = h-s
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
ans = 0
def rec(l, r, h, ans):
    if sum(h) == 0:
        return ans
    zero_index = [l-1]
    for i in range(l, r+1):
        if h[i] == 0 and abs(abs(zero_index[-1]) - i) <= 1:
            zero_index[-1] = i
        elif h[i] == 0:
            zero_index.append(i)
    zero_index.append(r+1)
    ans += len(zero_index) - 1
    h = [max(0, hi-1)for hi in h]
    zero_index = [l-1]
    for i in range(l, r+1):
        if h[i] == 0:
            zero_index.append(i)
    zero_index.append(r+1)
    for i in range(len(zero_index)-1):
        if abs(zero_index[i] - zero_index[i+1]) <= 1:
            continue
        ans = rec(zero_index[i]+1, zero_index[i+1]-1, h, ans)
    return ans
ans = rec(0, N-1, h, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
a = 0
while sum(h) > 0:
    lst = [i for i, x in enumerate(h) if x > 0]
    mx = min(lst)
    for i in range(len(lst) -1):
        if lst[i] + 1 == lst[i+1]:
            mx += 1
        else:
            break
    h = [x - 1 if i >= min(lst) and  i <= mx else x for i, x in enumerate(h)]
    a += 1
    print(h)
print(a)

Submission status: Wrong Answer

Solution code:
iN = int(input())
aH = [int(_) for _ in input().split()]

iC = 0
for _ in range(100):
    iM = max(aH)
    if iM == 0:
        break
    iH = aH.index(iM)
    if iH == iN-1:
        iC += iM - aH[iH-1]
        aH[iH] = aH[iH-1]
    elif iH == 0 :
        iR = 1
        while True:
            if aH[iH + iR] != iM:
                i2 = aH[iH+iR]
                iC += iM - i2
                for i in range(iH,iH+iR):
                    aH[i]=i2
                break
            else:
                iR += 1
                if iH +iR == iN:
                    iC += iM
                    for i in range(iH,iH+iR):
                        aH[i] =0
                    break
    else:
        iLM = aH[iH-1]
        iR = 1
        while True:
            if aH[iH +iR] != iM:
                i2 = aH[iH+iR]
                if i2 >= iLM:
                    iC += iM - i2
                    for i in range(iH,iH+iR):
                        aH[i]=i2
                else:
                    iC += iM -iLM
                    for i in range(iH,iH+iR):
                        aH[i]=iLM
                break
            else:
                iR += 1
                if iH +iR == iN:
                    iC += iM - iLM
                    for i in range(iH,iH+iR):
                        aH[i] =iLM
                    break
print(iC)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
h = list(map(int, input().split()))


counts = 0
counts += min(h)

h = np.array(h)
h = h - min(h)

for i in range(len(h) -1):
    if h[i] > h[i+1]:
        counts += h[i] + h[i+1]

print(counts)

Submission status: Wrong Answer

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

count = 0

for i in range(n):    
    while h[i] >= 1:
        wid = 0
        for l in range(i,n):
            if h[l] >= 1:
                    wid = wid + 1
            else:
                break
        print(wid)
        #widの分だけ水をやる
        for k in range(wid):
            h[i + k] = h[i+k] - 1
        print(h)
        count = count + 1

print(count)

Submission status: Wrong Answer

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

for _ in range(100000):
    status = 0
    for i, x in enumerate(H):

        if x != 0:
            H[i] = x - 1
            status = 1
        elif ((x == 0) and (status == 1)):
            break
        else:
            pass
    if sum(H) == 0:
        break

print(_ + 1)

Submission status: Wrong Answer

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

mi = min(H)
for i in range(N) :
    H[i] -= mi
ans += mi
#print(H,ans)
for i in range(N) :
    a = H[i]
    H[i] = 0
    for j in range(i+1,N+1) :
        if a <= H[j] :
            H[j] -= a
        else :
            
            ans += a-H[j]
            a = H[j]
            break
        if a == min(H[i:]) :
            ans += a
        
    #print(H)
    #print(ans)
print(ans)