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()))
dic = [[h[i],i] for i in range(N)]
dic.sort()

def isolate(n,lst,iso):
    lst[n] = None
    if n==0 or n==len(lst)-1:
        return iso
    elif lst[n-1]!=None and lst[n+1]!=None:
        iso +=1
    return iso

isolation = 1
table = [dic[i][1] for i in range(N)]
former = 0
ans = 0
for i in range(N):
    ans += (dic[i][0] - former) * isolation
    former = dic[i][0]
    isolation = isolate(dic[i][1],table,isolation)

print(ans)

Submission status: Wrong Answer

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

a = np.zeros(N)
h_min = min(h)
tmp = (h >= h_min+1)*1

cnt = 0
for idx, i in enumerate(tmp):
    if idx==0:
        a0 = i
        if i==1:
            cnt+=1
        continue
        
    if idx==a0:
        continue
    else:
        cnt+=1
else:
    if i==0:
        cnt-=1
        
print(cnt+h_min)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

global count 
global minval

def judge_max1(h,N):
    global minval
    N= len(h)
    change_countp = 0
    change_countn = 0
    flag_p = 0
    flag_n = 0
    for i in range(N-1):
        if h[i+1] < h[i]:
            if flag_p == 1:
                change_countp += 1
            flag_n = 1
            flag_p = 0
        elif h[i+1] > h[i]:
            if flag_n == 1:
                change_countn += 1  #下降から上昇に変化
                minval = i
            flag_p = 1
            flag_n = 0
    
    if change_countn == 0:
        return True
    else :
        return False
    
    
    
def recursive_f(h,N):
    global count,minval
    hmin = max([0,min(h)])
    count += hmin
    h = h - hmin
    if judge_max1(h,N):
        count += max(h)
    else :
        h = h - h[minval]
        count += h[minval]
        h1 = h[0:minval]
        h2 = h[minval:len(h)]
        recursive_f(h1,N)
        recursive_f(h2,N)
        
        
        
    



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

h = np.array(h)
count = 0

recursive_f(h,N)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
cnt = 0
def minus1(arr) :
  for i in range(len(arr)) :
    if(arr[i] != 0) : arr[i] -= 1
  return 0

def discover0(arr) :
  flag = [0, 0]
  cnt = 0
  for i in range(1, len(arr)) :
    if(arr[i-1] != 0 and arr[i] == 0 and flag[1] == 0) :
      flag[0] = 1
    elif(arr[i-1] == 0 and arr[i] != 0) :
      flag[1] = 1
    if(flag == [1, 1]) :
      flag = [0, 0]
      cnt += 1
  return cnt

for i in range(max(h)) :
  cnt += discover0(h)
  minus1(h)
  cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
cnt = 0
def minus1(arr) :
  for i in range(len(arr)) :
    if(arr[i] != 0) : arr[i] -= 1
  return 0

def discover0(arr) :
  flag = [0, 0]
  cnt = 0
  for i in range(1, len(arr)) :
    if(arr[i-1] != 0 and arr[i] == 0) :
      flag[0] = 1
    elif(arr[i-1] == 0 and arr[i] != 0) :
      flag[1] = 1
    
    if(flag == [1, 1]) :
      flag = [0, 0]
      cnt += 1
  return cnt

for i in range(max(h)) :
  cnt += discover0(h)
  minus1(h)
  cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
def f(arr):
    print(arr)
    if(sum(arr) == 0):
        return 0
    while(arr[0] == 0):
        arr.pop(0)
    while(arr[-1] == 0):
        arr.pop()
    if (min(arr) == 0):
        index = arr.index(0)
        return f(arr[0:index]) + f(arr[index: len(arr)])
    else:
        minval = min(arr)
        if (len(arr) == 1):
            return minval
        else:
            arr = list(map(lambda x: x- minval, arr))
            if(sum(arr)==0):
                return minval
            else:
                return f(arr) + minval
print(f(h))

Submission status: Wrong Answer

Solution code:
from itertools import*
from numpy import*
n,*a=map(int,open(0).read().split())
print(a)
if set(a)=={0}:
    print(0)
    exit()
a=array(a)
count=0
ans=0
while 1:
    count=min(a[a!=0])
    ans+=count*sum(k for k,v in groupby(a>0)if k==True)
    a=a-min(a[a!=0])
    a[a<0]=0
    if sum(a)==0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = input()
h = [int(x) for x in input().split()]
count = 0
while sum(h) != 0:
    htop = [1 if x == max(h) else 0 for x in h]
    h = [x-1 if x == max(h)  else x for x in h]
    htop = "".join([str(x) for x in htop])
    htop = htop.strip("0").split("0") 
    count += len(htop)

print(count)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = input()
h = [int(x) for x in input().split()]
count = 0
while sum(h) != 0:
    htop = [1 if x-(max(h)-1) >= 1 else 0 for x in h]
    h = [x if x-max(h) < 0 else x-1 for x in h]
    htop = "".join([str(x) for x in htop])
    htop = htop.strip("0").split("0") 
    count += len(htop)

print(count)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = input()
h = [int(x) for x in input().split()]
count = 0
while sum(h) != 0:
    htop = [1 if x-(max(h)-1) >= 1 else 0 for x in h]
    h = [x-1 if x-1 >= 0 else 0 for x in h]
    htop = "".join([str(x) for x in htop])
    htop = htop.strip("0").split("0") 
    count += len(htop)

print(count)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = input()
h = [int(x) for x in input().split()]
count = 0
while sum(h) != 0:
    htop = [1 if x-(max(h)-1) >= 1 else 0 for x in h]
    h = [x-1 if x-1 >= 0 else 0 for x in h]
    htop = "".join([str(x) for x in htop])
    htop = htop.split("0") 
    count += len(htop)

print(count)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = input()
h = "".join(input().split()) # h は数字の文字列
count = 0
while sum([int(x) for x in h]) != 0:
    h2 = [x for x in h.strip("0").split("0")]
    count += len(h2)
    h3 = "".join(h2)
    h4 = [int(x)-1 for x in h3]
    h = "".join([str(x) for x in h4])
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
H=list(map(int,input().split()))
ans=max(H)
tmp=H[0]
for i in range(1,len(H)-1):
  tmp=max(H[i],tmp)
  if H[i-1]>H[i] and H[i]<H[i+1]:
    ans+=tmp-H[i]
    tmp=H[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input()) + 1
l = list(map(int, input().split()))
l.append(0)

count = 0

for i in range(n):
	while(l[i] > 0):
		for j in range(i + 1, n):
			if l[j] == 0:
				break
		for k in range(i, j):
			l[k] -= 1
		count += 1
		print(l)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
Max = 1
res = 0
pre_left = 0
while True:
  Max = 0
  w = 0
  left = 0
  right = n
  flag = False
  for i in range(n):
    if lst[i] > 0 and not flag:
      w = 1
      pre_left = left
      left = i
      flag = True
    elif lst[i] > 0 and flag:
      w += 1
    elif lst[i] <= 0 and flag:
      if Max < w:
        Max = w
        right = i
        flag = False
      else:
        left = pre_left
      w = 0
  if w == n:
    Max = n
  if Max == 0:
    break
  for i in range(left, right):
    lst[i] -= 1
  res += 1
      
print(res)

Submission status: Wrong Answer

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

loc_max = h[0]
count = 0

for i in range(1, N):
    if h[i] >= loc_max:
        loc_max = h[i]
    if h[i] < h[i-1]:
        count = count + loc_max - h[i]
        loc_max = 0
    if i == N-1:
        count = count + h[i]

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
h_unique = [h[0]]
for i in range(1, len(h)):
    if h_unique[-1] == h[i]:
        continue
    h_unique.append(h[i])


def minimum_value_index(arr, start, end):
    min_min = 101
    min_index = -1
    for i in range(start + 1, end - 1):
        if arr[i-1] > arr[i] and arr[i+1] > arr[i]:
            if min_min > arr[i]:
                min_min = arr[i]
                min_index = i
    return min_index


def max_value(arr, start, end):
    m = arr[start]
    for i in range(start + 1, end):
        if m < arr[i]:
            m = arr[i]
    return m


def count(arr, start, end, base_height):
    min_index = minimum_value_index(arr, start, end)
    if 0 > min_index:
        return max_value(arr, start, end) - base_height
    min_height = arr[min_index]
    left = count(arr, start, min_index, min_height - base_height)
    right = count(arr, min_index, end, min_height - base_height)
    return min_height + left + right 
    

print(count(h_unique, 0, len(h_unique), 0))

Submission status: Wrong Answer

Solution code:
N = int(input())
H = list(map(int, input().split()))
H = [h - min(H) for h in H]

ans = 0
for i in range(N-1):
    diff = H[i+1] - H[i]
    if i != N-2:
        if diff < 0:
            ans += abs(diff)
    else:
        if diff < 0:
            ans += abs(diff)
        else:
            ans += H[-1]

print(ans + min(H))

Submission status: Wrong Answer

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

ans = 0
for i in range(N-1):
    diff = H[i+1] - H[i]
    if i != N-2:
        if diff < 0:
            ans += abs(diff)
    else:
        if diff < 0:
            ans += abs(diff)
        else:
            ans += H[-1]

print(ans + min(H))

Submission status: Wrong Answer

Solution code:
n = int(input())
h = input().split()
h = [int(i) for i in h]
sum,sub = 0,0
for i in range(1,n):
	if h[i-1] > h[i]:
		sum += h[i-1] - sub
		sub = h[i]
if h[len(h)-2] < h[len(h)-1]:
	sum += h[len(h)-1] - sub
print(sum)

Submission status: Wrong Answer

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

ans = 0
check = 0
while(True):
    for i in range(N):
        if i == 0:
            check = 0
        if check == 0:
            if h[i] != 0:
                check = 1
                ans += 1
                h[i] -=1
        if check == 1:
            if h[i] != 0:
                h[i] -= 1
            else:
                check = 0
    if(sum(h)==0):
        break
            
print(ans)

Submission status: Wrong Answer

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

i = 0
res = []
while True:
    for h in hn:
        if h > 0:
            res.append(h-1)
        else:
            res.append(h)
    hn = res
    res = []
    if sum(hn) == 0:
        print(i)
        break
    i += 1

Submission status: Wrong Answer

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

for t in range(len(list)):
    list[t] = int(list[t])

cnt = 0

for idx in range(n):
    t_min = min(list[idx:n])
    for idx2 in range(idx,n):
        if 0 != list[idx2]:
            break
        else:
            list[idx2] = list[idx2]-1
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split(" ")))
counter = 0
ans = 0
for i in range(N-1):
    if h[i] <= h[i+1]:
        continue
    else:
        ans += h[i] - counter
        counter = h[i+1]
if h[N-1] > h[N-2]:
    ans += h[N-1] - counter
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split(" ")))
counter = 0
ans = 0
for i in range(N-1):
    if h[i] <= h[i+1]:
        continue
    else:
        ans += h[i] - counter
        counter = h[i+1]
if h[N-1] > h[N-2]:
    ans += h[N-1] - h[N-2]
elif h[N-1] > h[N-2]:
    ans += h[N-1] - counter
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split(" ")))
counter = 0
ans = 0
for i in range(N-1):
    if h[i] <= h[i+1]:
        continue
    else:
        ans += h[i] - counter
        counter = h[i+1]
if h[N-1] > h[N-2]:
    ans += h[N-1] - h[N-2]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

#途中 メモ残すため提出

def mizuyari(ary):
    n = 0
    ary2 = distinctAry(ary)
    
    #全体に水遣り
    if min(ary) > 0:
        n += 1 + mizuyari([s - 1 for s in ary2])
    
    #一部に水遣り
    else:
        print(ary2)
        
    return n

#配列の重複消し
def distinctAry(ary):
    
    for i, j in enumerate(ary):
        
        if i + 1 >= len(ary):
            break;
        else:
            if (ary[i] == ary[i + 1]):
                del(ary[i])
    return ary

#main start
import copy

n = int(input())
ary = [int(s) for s in input().split()]

mizuyari(ary)

Submission status: Wrong Answer

Solution code:
#N本の花があり、それぞれ1,2....,Nと番号が振られている
#最初全ての花の高さは0
#h=[h_1,h_2,...,h_n]が与えられる
#整数l,rを指定して、l<=x<=rを満たす花xの高さを1増やす、という行為をする
#花xの高さがh_xになるための最小水やり回数を求めよ
n = int(input())
flower_height = list(map(int, input().split()))
count=0
def mizuyari(a):
    return a-1
#(0ではない)一番左端の高さに注目する
#その高さから0の高さにぶち当たるまで右に進める
#進んだところに水やりする
#これを繰り返す
for i in range(n):
    j=i
    while flower_height[i]!=0:
        while i < n-1:
            if flower_height[i+1] != 0: i+=1
            else: break
        flower_height = list(map(mizuyari,flower_height[:i+1])) + flower_height[i+1:]
        i=j
        count += 1

Submission status: Wrong Answer

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


def mizuyari(*f):
    print(f)
    if len(f) == 0:
        return
    min_i = f.index(min(f))
    if f[min_i] != 0:
        global ans
        ans += f[min_i]
        print('ans=', ans)
        f = [i - f[min_i] for i in f]
    print(f)
    if f[min_i] == 0:
        mizuyari(*f[:min_i])
        mizuyari(*f[min_i + 1:])


l = []
for n in range(N):
    l.append(0)
mizuyari(*H)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
	N = int(input())
	h = [int(i) for i in input().split()]
	return N * max(h) - sum(h)

print(solve())

Submission status: Wrong Answer

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

peak = []
trough = []
before = h[0]
for a, b in zip(h[:-1], h[1:]):
    after = b - a
    if after == 0:
        continue
    elif before > 0 and after < 0:
        peak.append(a)
    elif before < 0 and after > 0:
        trough.append(a)
    before = after

print(sum(peak) - sum(trough))

Submission status: Wrong Answer

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

peak = []
trough = []
h = [0] + h + [0]
for a, b, c in zip(h[:-2], h[1:-1], h[2:]):
    ab = b - a
    bc = c - b
    if ab * bc < 0:
        if bc < 0:
            peak.append(b)
        else:
            trough.append(b)

print(sum(peak) - sum(trough))

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
i = 0
start = 0
end = 0
ans = 0
while True:
    i = 0
    for y in range(n):
        if h[y] != 0:
            start = y
            break
    for x in range(start,n):
        if h[x] != 0:
            h[x] -= 1
            if x == n-1:
                ans += 1
        else:
            start = 0
            i = 0
            ans += 1
            break
    if h.count(0) == n:
        break
print(ans)

Submission status: Wrong Answer

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

for t in range(len(list)):
    list[t] = int(list[t])

cnt = 0

for idx in range(n):
    if 0 != list[idx]:
        for idx2 in range(idx,n):
            if 0 == list[idx2]:
                break
            else:
                list[idx2] = int(list[idx2])-1
        cnt += 1
    else:
        if idx == n-1:
            break

print(cnt)

Submission status: Wrong Answer

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

def nextgen(comb):
    lis = comb[0]
    j = comb[1]
    for i in range(len(lis)-1):
        if (i != len(lis) and (lis[i] == 0 and lis[i+1] != 0)) or (i == 0 and lis[i] != 0):
            j += 1
        if lis[i] != 0:
            lis[i] -= 1
    if lis[len(lis)-1] != 0:
        lis[len(lis)-1] -= 1
    return [lis, j]

comb = [heights, 0]
while (comb[0].count(0) != len(comb[0])):
    comb = nextgen(comb)

print(comb[1])

Submission status: Wrong Answer

Solution code:
num = 0
n = int(input())
h = [int(i) for i in input().split()]
while h.count(min(h))<n:
  top = h.index(max(h))
  if top==0:
    num += h[0]-h[1]
    h[0] = h[1]
  elif top==(n-1):
    num += h[n-1]-h[n-2]
    h[n-1] = h[n-2]
  else:
    nx = [h[top-1], h[top+1]]
    nx.sort()
    if h[top]==nx[1]:
      num += h[top]-nx[0]
      h[top] = nx[0]
    else:
      num += h[top]-nx[1]
      h[top] = nx[1]
print(num)

Submission status: Wrong Answer

Solution code:
def calc_range_num(h,height,max_height,ans):#各階層にいくつ区間があるか
    for i in range(len(h)):
        if h[i]>=height and height != 0:
            if i+1<len(h) and h[i]>h[i+1] and h[i+1] <=height:
            #基本的には、高さが下がったところでインクリメント
                ans+=1
            elif i==len(h)-1 and h[i]>height:
                ans+=1
    height+=1
    if height>max_height:
        return ans
    else:
        ans = calc_range_num(h,height,max_height,ans)
    return ans
N = int(input())
h = list(map(int, input().split()))
max_height=max(h)
ans=0
print(calc_range_num(h,1,max_height,ans))

Submission status: Wrong Answer

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

a = 0
for i in range(len(h)):
    a = a + max(h) - h[i]

print(a)

Submission status: Wrong Answer

Solution code:
def calc_range_num(h,height,max_height,ans):#各階層にいくつ区間があるか
    for i in range(len(h)):
        if h[i]>=height:
            if i==0:
                ans+=1
            elif h[i]>h[i-1] and height!=1 and h[i]==height:#＞で見てたらWA
                ans+=1
    height+=1
    if height>max_height:
        return ans
    else:
        ans = calc_range_num(h,height,max_height,ans)
    return ans
            
N = int(input())
h = list(map(int, input().split()))
max_height=max(h)
ans=0
print(calc_range_num(h,1,max_height,ans))

Submission status: Wrong Answer

Solution code:
def calc_range_num(h,height,max_height,ans):#各階層にいくつ区間があるか
    for i in range(len(h)):
        if h[i]==height:
            if i==0:
                ans+=1
            elif h[i]!=h[i-1] and height!=1:
                ans+=1
    height+=1
    if height>max_height:
        return ans
    else:
        ans = calc_range_num(h,height,max_height,ans)
    return ans
N = int(input())
h = list(map(int, input().split()))
max_height=max(h)
ans=0
print(calc_range_num(h,1,max_height,ans))

Submission status: Wrong Answer

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

c = 0
l = 0
while True:
    # update r
    r = l
    min_num = 1e3
    while r != n and hn[r] != 0:
        min_num = min(min_num, hn[r])
        r += 1
    
    # watering
    for i in range(l, r):
        hn[i] -= min_num
    c += min_num

    # update l
    while l != n and hn[l] == 0:
        l += 1
    if l == n:
        break
print(c)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from sys import stdin


############################################

#from sys import stdin
import numpy as np

# read data for n sequences.
n = int(stdin.readline())
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)

out = 0

for i,x in enumerate(data):
    
    # pick smallest data not zero.
    for offset in range(0, len(data)-i):
        if data[i+offset] < 1:
            break
        if offset == len(data)-i-1:
            offset += 1
    if not data[i]==0:
        if len(data[i:i+offset])>1:
            minnum = np.min(data[i:i+offset])
        else:
            minnum = 0
        for x in range(offset):
            data[i+x] -= minnum
        
        out += minnum
        out += data[i]
#    print(data)
#    print(offset)

   
    
           
print(int(out))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from sys import stdin

#from sys import stdin
import numpy as np

# read data for n sequences.
n = int(stdin.readline())
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)

out = 0

for i,x in enumerate(data):
    
    # pick smallest data not zero.
    for offset in range(0, len(data)-i):
        if data[i+offset] < 1:
            break
        if offset == len(data)-i-1:
            offset += 1
    if not data[i]==0:
        if len(data[i:i+offset])>1:
            minnum = np.min(data[i:i+offset])
        else:
            minnum = data[i]
        for x in range(offset):
            data[i+x] -= minnum
        out += minnum
        out += data[i]
#    print(data)
#    print(offset)
           
print(int(out))

Submission status: Wrong Answer

Solution code:
from sys import stdin

############################################

#from sys import stdin
import numpy as np

# read data for n sequences.
n = int(stdin.readline())
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)

out = 0

for i,x in enumerate(data):
    
    # pick smallest data not zero.
    for offset in range(0, len(data)-i):
        if data[i+offset] < 1:
            break
        if offset == len(data)-i-1:
            offset += 1
    if not data[i]==0:
        if len(data[i:i+offset])>1:
            minnum = np.min(data[i:i+offset])
        else:
            minnum = data[i]
        for x in range(offset):
            data[i+x] -= minnum
        out += minnum
        out += data[i]
#    print(data)
#    print(offset)

   
    
           
print(int(out))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

#from sys import stdin

#N= int(raw_input())
#h=[]
#h.extend( map(int, stdin.readline().split())   )

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



ans = h[0]
for i in range(1,N):
  ans += max(0, h[i]-h[i-1])
  #print i, max(0,h[i]-h[i-1]), h[i], h[i-1]
#print N, h
print ans, h

Submission status: Wrong Answer

Solution code:
a = [int(i) for i in input().split()] 
n = 0
num = a[0]
for i in a:
  max = a[0]
  
  
  if i > a[n-1] and n > 0:
    num += (i-a[n-1])
  n += 1
print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
t = []
count = 0
mx = max(s)

for i in range(n):
	t.append(0)
	
flag = True

while flag:
	for i in range(n):
		if s[i] != 0:
			s[i] -= 1
	count += 1
	if s == t:
		flag = False

print(count)

Submission status: Wrong Answer

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

mmm=int(max(lit))*n
ans=mmm-int(sum(lit))
print(ans)

Submission status: Wrong Answer

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

print(lit)
mmm=int(max(lit))*n
ans=mmm-int(sum(lit))
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int,input().split()))
co = 0
k = 0
for i in range(a):
  if k <= b[i]:
    k = b[i]
    if i == a-1:
      co += k
  else:
    co += k - b[i]
    k = 0
    if i == a-1:
      co += b[i]
    
print(co)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
h += [0]
add = True
ans = 0
for n in range(100):
    for i in range(N+1):
        if h[i] != 0:
            h[i] -= 1
            add = True
        else:
            if add:
                ans += 1
            add = False
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = [int(i) for i in input().split()]
import numpy as np
h = np.array(h)
zero = np.array([int(0) for i in range(len(h))])

def calc(h, zero, minus):
    for k in range(len(h)):
        if minus[k] != 0:
            for w in range(k+1, len(h)):
                if minus[w] == 0:
                    zero[k:w] = zero[k:w] + 1
                    return
                elif w == len(h) - 1:
                    zero[k::] = zero[k::] + 1
                    return

def main(h, zero):
    for i in range(1, 101):
        minus = h - zero
        if np.sum(minus) == 0:
            print(i-1)
            return
        calc(h ,zero, minus)
main(h, zero)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
h = [int(i) for i in input().split()]
h = np.array(h)
zero = np.array([int(0) for i in range(len(h))])

def calc(h, zero, minus):
    for k in range(len(h)):
        if minus[k] != 0:
            for w in range(k+1, len(h)):
                if minus[w] == 0:
                    zero[k:w] = zero[k:w] + 1
                    return

def main(h, zero):
    for i in range(1, 101):
        minus = h - zero
        if np.sum(minus) == 0:
            print(i-1)
            return
        if np.min(minus) != 0:
            zero += 1
        else:
            calc(h ,zero, minus)
main(h, zero)

Submission status: Wrong Answer

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

s = 0
for i in range(1, N):
    s += max(0, h[i] - h[i - 1])

print(s)

Submission status: Wrong Answer

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

for i in range(1, N):
    h[i] = max(0, h[i] - h[i - 1])

print(sum(h))

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
a=0
for i in range(1,max(h)+1):
    s=0
    while s<n:
        if h[s]>=i:
            a+=1
        s+=1
print(a)

Submission status: Wrong Answer

Solution code:
ans = 0
n = int(input())
a = [0]
for i in input().split():
    a.append(int(i))
for i in range(n):
    if a[i] > a[i-1]:
        ans += a[i] - a[i - 1]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
N = int(input())
L = np.array(list(map(int, input().split())))

cnt = 0
while np.any(L > 0):
    for i in range(N):
        if L[i] > 0:
            start = i
            end = i + 1
            for j in range(start+1, N):
                end = j
                if not L[j] > 0:
                    break
                end += 1
            break
        
    
    cnt += L[start:end].min()
    L[start:end] -= L[start:end].min()
    print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
N = int(input())
L = np.array(list(map(int, input().split())))

cnt = 0
while np.any(L > 0):
    for i in range(N):
        if L[i] > 0:
            start = i
            end = i + 1
            for j in range(start+1, N):
                end = j
                if not L[j] > 0:
                    break
                end += 1
            break
        
    
    cnt += L[start:end].min()
    L[start:end] -= L[start:end].min()
    print(L, cnt, start, end)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

count = 0
def recur(array):
    global count
    if len(array) == 0 :
        pass
    else:
        print('plus :', min(array))
        count += min(array)
        array = array - min(array)
        for i in range(len(array)):
            if array[i] == 0:
                array_1 = array[:i]
                array_2 = array[i+1:]
                break
        recur(array_1)
        recur(array_2)
    return count

print(recur(array))

Submission status: Wrong Answer

Solution code:
n = int(input())
h_list = [int(_) for _ in input().split()]
ans = 0 
while sum(h_list) != 0:
    # 0で区切られた、1以上の数のかたまりを数える
    # 要素が全て1以上ならansに+1して次のループ
    if h_list.count(0) == 0:
        ans += 1
    else:
        for i in range(0,n):
            # 1以上から0に下がった時にかたまりをカウント
            if i != 0 and h_list[i] == 0 and h_list[i - 1] != 0:
                ans += 1
            elif i == n and h_list[i] != 0:
                ans += 1
    # 1以上の箇所を1段ずつ落とす
    for j in range(n):
        if h_list[j] != 0:
            h_list[j] -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def get_nonzero_range(A):
    start, end = None, None
    N = len(A)
    for i in range(N):
        if A[i] != 0:
            start = i
            for j in range(i+1, N):
                if A[j] == 0:
                    end = j
                    return start, end
    else:
        return start, end

N = int(input())
H = list(map(int, input().split()))
H.append(0)
num = 0
print(H)
while True:
    start, end = get_nonzero_range(H)
    if start == None:
        break
    else:
        for i in range(start, end):
            H[i] -= 1
        num += 1
print(num)

Submission status: Wrong Answer

Solution code:
def get_nonzero_range(A):
    start, end = None, None
    N = len(A)
    for i in range(N):
        if A[i] != 0:
            start = i
            for j in range(i+1, N):
                if A[j] == 0:
                    end = j
                    return start, end
    else:
        return start, end

N = int(input())
H = list(map(int, input().split()))
H.append(0)
num = 0
print(H)
while True:
    start, end = get_nonzero_range(H)
    print(start, end)
    if start == None:
        break
    else:
        for i in range(start, end):
            H[i] -= 1
        num += 1
print(num)

Submission status: Wrong Answer

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

ans = 0
while sum(L) :
    ans += 1
    for i in range(N) :
        if L[i] == 0 :
            continue
        L[i] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
nums = []
nums.append(int(input()))

for i in range(1,100000):
    if nums[i - 1] % 2 == 0:
        nums.append(nums[i - 1] // 2)
    else:
        nums.append(nums[i - 1] * 3 + 1)
    if i >= 3 and nums[i] == 4 and nums[i - 3] == 4:
        print(i + 1)
        break

Submission status: Wrong Answer

Solution code:
nums = []
nums.append(int(input()))

for i in range(1,100000):
    if nums[i - 1] % 2 == 0:
        nums.append(nums[i - 1] // 2)
    else:
        nums.append(nums[i - 1] * 3 + 1)
    if i >= 3 and nums[i] == 4 and nums[i - 3] == 4:
        print(i)