TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
N = int(input())
# h = list(map(int, input().split()))
h = [0]
for _ in range(N):
    h.append(int(input()))
answer = 0
for i in range(1, N+1):
    answer += max(H[i] - H[i-1], 0)

print(answer)

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+1):
    answer += max(H[i] - H[i-1], 0)

print(answer)

Verdicts: Runtime Error

Accepted
Problem: 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.

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

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

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

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

print(cnt)


import sys

N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
if sum(h) == 0:
    print(0)
    sys.exit()

while True:
    for i in range(N):
        if h[i] != 0:
            start = i
            break

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

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

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

print(cnt)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
    



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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

def count(h_list):
    if len(h_list) == 0:
        return 0
    if len(h_list) == 1:
        return h_list[0]
    if (h_list != 0).all():
        return 1 + count(h_list - 1)
    elif (h_list == 1).all():
        return 1
    return sum([count(x) for x in divide_by_zero(h_list)])


def divide_by_zero(arr):
    non_zero = []
    for ar in arr:
        if ar == 0:
            if non_zero:
                yield np.array(non_zero)
                non_zero = []
        else:
            non_zero.append(ar)
    yield np.array(non_zero)

n = int(input())
h_list = np.array([int(x) for x in input().split(" ")])
print(count(h_list))


def count(h_list):
    if len(h_list) == 0:
        return 0
    if len(h_list) == 1:
        return h_list[0]
    if 0 not in h_list:
        return 1 + count([x-1 for x in h_list])
    elif all(x == 1 for x in h_list):
        return 1
    return sum([count(x) for x in divide_by_zero(h_list)])


def divide_by_zero(arr):
    non_zero = []
    for ar in arr:
        if ar == 0:
            if non_zero:
                yield non_zero
                non_zero = []
        else:
            non_zero.append(ar)
    yield non_zero


n = int(input())
h_list = [int(x) for x in input().split(" ")]
print(count(h_list))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
h=list(map(int,input().split()))
f=[0]*n
cnt=0
while 1:
    flag=0
    for i in range(n):
        if h[i]!=f[i]:
            f[i]+=1
            flag=1
        elif h[i]==f[i] and flag==1:
            cnt+=1
            flag=0
    if flag:==1
        cnt+=1

    if h == f:
        break

print(cnt)


n=int(input())
h=list(map(int,input().split()))
f=[0]*n
cnt=0
while 1:
    flag=0
    for i in range(n):
        if h[i]!=f[i]:
            f[i]+=1
            flag=1
        elif h[i]==f[i] and flag==1:
            cnt+=1
            flag=0
    if flag==1:
        cnt+=1

    if h==f:
        break

print(cnt)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
h=list(map(int, input().split()))
ans=0

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

print(ans)

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

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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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])
    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]:
            en = i+1
        if st != -1 and en != -1:
            print(st,en)
            tmp.append(tmp[0][st:en])
            st,en = -1,-1
    print(tmp)
    tmp.popleft()
print(count)

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
    tmp.popleft()
print(count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=max(0,x[i+1]-x[i])
print(ans)

n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=max(0,x[i+1]-x[i])
print(ans+x[0])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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


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)


n = int(input())
flowers = list(map(int,("0 " + input()).split(' ')))
diff = []
ans = 0
for i in range(1,n + 1):
    diff.append(flowers[i] - flowers[i - 1])
# print(diff)
for d in diff:
    if d > 0:
        ans += d
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

n,*a=map(int,open(0).read().split())
ans=0
pre=0
for i in a:
    if i>pre:
        ans+=i-pre
    pre=i
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
h=list(map(int,input().split()))
cnt=0
while set(h)=={0}
  if h not in 0:
    for i in range(len(h)):
      h[i]=h[i]-min(h)
      cnt+=min(h)
  else:
    for i in range(len(h)):
      l=[]
      if h[i]==0:
      else:
        l.append(h[i])
        continue
      cnt+=min(l)
print(cnt)

n=int(input())
h=list(map(int,input().split()))
cnt=0
l=[]
while set(h)!={0}:
  if h.count(0)==0:
    cnt+=min(h)
    for i in range(len(h)):
      h[i]=h[i]-min(h)
  else:
    for i in range(len(h)):      
      if h[i]==0:
        l.append(h[i])
      else:
        l.append(h[i])
        continue
      cnt+=min(l)
      l=[]
print(cnt)

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

Verdicts: Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
list1 = list(map(int,input().split()))
cout = 0 
now_water = 0 
i = 0
def func(flower):
	global cout
	global i
	if flower == n-1: 
		if list1[flower] <= now_water:
			cout += 1
			i = flower + 1
			return
		else:
			cout += 1
			i = flower + 1
			return

	elif list1[flower] <= now_water: 
		cout += 1 
		i = flower + 1
		return
	else:
		func(flower + 1)

while now_water <= max(list1): 
	i = 0
	while i < n: 
		if list1[i] > now_water:
			func(i)
		else:
			i+=1
	now_water += 1

n = int(input())
list1 = list(map(int,input().split()))
cout = 0 
now_water = 0 
i = 0
def func(flower):
	global cout
	global i
	if flower == n-1: 
		if list1[flower] <= now_water:
			cout += 1
			i = flower + 1
			return
		else:
			cout += 1
			i = flower + 1
			return

	elif list1[flower] <= now_water: 
		cout += 1 
		i = flower + 1
		return
	else:
		func(flower + 1)

while now_water <= max(list1): 
	i = 0
	while i < n: 
		if list1[i] > now_water:
			func(i)
		else:
			i+=1
	now_water += 1





print(cout)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
H = list(map(int, input().split()))
ans = 0

while max(H) > 0:
    grp = [[]]
    for i, h in enumerate(H):
        if h == 0:
            if len(grp[-1]) > 0:
                grp.append([])
        else:
            grp[-1].append((i, h))
    for g in grp:
        mi = min([h for _, h in g])
        ans += mi
        for i, _ in g:
            H[i] -= mi

print(ans)


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

while max(H) > 0:
    grp = [[]]
    for i, h in enumerate(H):
        if h == 0:
            if len(grp[-1]) > 0:
                grp.append([])
        else:
            grp[-1].append((i, h))
    for g in grp:
        if len(g) == 0:
            continue
        mi = min([h for _, h in g])
        ans += mi
        for i, _ in g:
            H[i] -= mi

print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    n = int(input())
    h = [list(map(int, input().split()))]
    ans = h[0]
    for i in range(n-1):
        if h[i+1] > h[i]:
            ans += h[i + 1]-h[i]
    print(ans)


if __name__ == '__main__':
    main()


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


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
h = list(map(int,input().split()))


def WaterTime(list):
    times=0
    if list[0]!=0:
        times+=1
    for i in range(1,len(list)):
        if list[i]!=0 and list[i-1]==0:
            times+=1
    return times

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

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


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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
h = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(len(h)):
    print(h[i])
    if tmp < h[i]:
        ans += h[i] - tmp
    tmp = h[i]
print(ans)

n = int(input())
h = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(len(h)):
    if tmp < h[i]:
        ans += h[i] - tmp
    tmp = h[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
h=list(map(int,input().split()))
ltani=h[0]
yama=h[0]
mizu=0
if n==1:
    print(max(h))
elif 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]:
            rtani=h[i]
            mizu=mizu+yama-min(ltani,rtani)
            ltani=h[i]
        elif h[i-1]<h[i] and h[i]>h[i+1]:
            yama=h[i]
    if h[n-2]>h[n-1]:
        rtani=h[i]
        mizu=mizu+yama-min(ltani,rtani)
        ltani=h[i]
    else:
        yama=h[n-1]
        mizu=mizu+yama-ltani
    mizu=mizu+min(h)
    print(mizu)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = int(input())
l = {s}
if s % 2 == 0:
    s //= 2
else:
    s = s * 3 + 1
i = 1
while s not in l:
    l.add(s)
    if s % 2 == 0:
        s //= 2
    else:
        s = s * 3 + 1
    i += 1
else:
    i += 1
print(i)

n = int(input())
s = list(map(int, input().split()))
count = 0
sidx = 0

ls = [s]
count = 0
while len(ls) != 0:
    l = ls.pop()
    mins = min(l)
    for i in range(len(l)):
        l[i] -= mins
    count += mins
    tmpl = []
    for i in l:
        if i == 0:
            if len(tmpl) != 0:
                ls.append(tmpl)
            tmpl = []
        else:
            tmpl.append(i)
    else:
        if len(tmpl) != 0:
            ls.append(tmpl)

print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
h = list(map(int, input().split()))
hantei = [0 for _ in range(n)]
hantei.append(1)
result = 0
h.append(10*3)

while any(hantei[i] != 1 for i in range(n)):
    min_h = min(h)
    cost = 0
    for i in range(len(h)):
        if hantei[i]==1:
            result += cost
            cost = 0
            h[i] = 10**3
        else:
            h[i] -= min_h
            if h[i] == 0:
                hantei[i] = 1
            cost = min_
print(result)

n = int(input())
h = list(map(int, input().split()))
hantei = [0 for _ in range(n)]
hantei.append(1)
result = 0
h.append(10*3)

while any(hantei[i] != 1 for i in range(n)):
    min_h = min(h)
    cost = 0
    for i in range(len(h)):
        if hantei[i]==1:
            result += cost
            cost = 0
            h[i] = 10**3
        else:
            h[i] -= min_h
            if h[i] == 0:
                hantei[i] = 1
            cost = min_h
print(result)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n, *H = map(int, open(0).read().split())

inc = True
peaks = [], []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            peaks.append(h0)
            inc = False
    else:
        if h0 < h1:
            peaks.append(-h0)
            inc = True
if inc:
    peaks.append(H[-1])
print(sum(peaks))

n, *H = map(int, open(0).read().split())

inc = True
peaks = []
for h0, h1 in zip(H, H[1:]):
    if inc:
        if h0 > h1:
            peaks.append(h0)
            inc = False
    else:
        if h0 < h1:
            peaks.append(-h0)
            inc = True
if inc:
    peaks.append(H[-1])
print(sum(peaks))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
h=list(map(int, input().split()))
ans=0
num=0
for i in range(n):
  if num<h[i]:
    ans+=h[i]-num
  cnt=h[i]
print(ans)

n=int(input())
h=list(map(int, input().split()))
ans=0
num=0
for i in range(n):
  if num<h[i]:
    ans+=h[i]-num
  num=h[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:n])-m
print(w)

n=int(input())
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:n])-m
print(w)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
s = list(int(input()))
cost = s[0]
for i in range(1, n):
    if s[i - 1] < s[i]:
        cost += s[i] - s[i - 1]
print(cost)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
h = list(map(int, input().split()))
f_h = [0 for i in range(N)]
judge = [False if f_h[i] != h[i] else True for i in range(N)]

ct = 0
while False in judge:
    flg = 0
    for i in range(N):
        if judge[i] is False:
            flg = 1
            f_h[i] += 1
            if f_h[i] == h[i]:
                judge[i] = True
        else:
            if flg == 1:
                ct += 1
                flg = 0
            else:
                pass
print(ct)


N = int(input())
h = list(map(int, input().split()))
f_h = [0 for i in range(N)]
judge = [False if f_h[i] != h[i] else True for i in range(N)]

ct = 0
while False in judge:
    flg = 0
    for i in range(N):
        if judge[i] is False:
            if i == N-1:
                f_h[i] += 1
                ct += 1
                if f_h[i] == h[i]:
                    judge[i] = True
            else:
                flg = 1
                f_h[i] += 1
                if f_h[i] == h[i]:
                    judge[i] = True
        else:
            if flg == 1:
                ct += 1
                flg = 0
            else:
                pass
print(ct)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

import numpy as np
import sys
count = 0
N = int(input())
h = list(map(int, input().split()))

h = map(lambda x:  x-min(h) ,h)
count =+ min(h)
if max(h) == 0:
  return count

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

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)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = input()
H = map(int, input().split())

Hk = set()
for h in H:
  Hk.add(h)

def po(h, s, e):
  if h >= Hk[-1]:
    return 1
  posS = s
  hit = False
  cnt = 0
  for posE in range(s, e+1):
    if posE >= e or H[posE] <= Hk[h]:
      hit or= (posE < e)
	if posS < posE:
      cnt += po(h+1, posS, posE)
  if hit:
    cnt += 1
  return cnt



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

Hk = set([0])
for h in H:
  Hk.add(h)
Hk = sorted(Hk)

def po(h, s, e):
  posS = s
  cnt = 0
  for posE in range(s, e+1):
    if posE >= e or H[posE] <= Hk[h]:
      if posS < posE:
        cnt += po(h+1, posS, posE)
      posS = posE + 1
  if h > 0:
    cnt += Hk[h] - Hk[h-1]
  return cnt

print(po(0, 0, len(H)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
n=int(input())
h=list(map(int,input().split()))
h.insert(0,0)
h.append(0)
p=max(h)
arr=np.array(h)
cnt=0
for i in range(p,1,-1):
    x=np.copy(arr)
    x[x!=i]=0
    x[x==i]=1
    temp=np.arange(len(x))
    temp[x>0]=0
    np.maximum.accumulate(temp,out=temp)
    left=temp
    x_reversed=x[::-1]
    temp=np.arange(len(x))
    temp[x_reversed>0]=0
    np.maximum.accumulate(temp,out=temp)
    right=len(x)-1-temp[::-1]
    y=right-left-1
    y[x==0]=0  
    z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)
    cnt+=len(z[0])
    arr=arr-x
print(cnt)

    
    

import numpy as np
n=int(input())
h=list(map(int,input().split()))
h.insert(0,0)
h.append(0)
p=max(h)
arr=np.array(h)
cnt=0
for i in range(p,0,-1):
    x=np.copy(arr)
    x[x!=i]=0
    x[x==i]=1
    temp=np.arange(len(x))
    temp[x>0]=0
    np.maximum.accumulate(temp,out=temp)
    left=temp
    x_reversed=x[::-1]
    temp=np.arange(len(x))
    temp[x_reversed>0]=0
    np.maximum.accumulate(temp,out=temp)
    right=len(x)-1-temp[::-1]
    y=right-left-1
    y[x==0]=0  
    z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)
    cnt+=len(z[0])
    arr=arr-x
print(cnt)

    
    

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)) 

N = int(input())
h = list(map(int,input().split()))
def f(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)) 

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  new_list = [x - min_h for x in h_list]
  i = new_list.index(0)
  return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(allwater(height))

def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  h_list = list(map(lambda x:x-minh, h_list))
  i = h_list.index(0)
  return min_h + all_water(h_list[:i]) + all_water(h_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(allwater(height))

def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  new_list = list(map(lambda x:x-minh, h_list))
  i = new_list.index(0)
  return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(allwater(height))

def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  new_list = [x - min_h for x in h_list]
  i = new_list.index(0)
  return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(all_water(height))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
h = list(map(int, input().split()))


def mizuyari(partial_list):
    count = 0
    print(partial_list)
    if len(partial_list) == 0:
        print('end return------------ 0 ')
        return 0
    if len(partial_list) == 1:
        print('end return------' + str(partial_list[0]))
        return partial_list[0]
    
    if min(partial_list) != 0:
        count += min(partial_list)
        print('count --------' + str(min(partial_list)))
        partial_list = list(map(lambda x: x-min(partial_list), partial_list))
    zero_index = []
    
    for i in range(len(partial_list)):
        if partial_list[i] == 0:
            zero_index.append(i)
    print(zero_index)
    bunkatsu = []
    bunkatsu.append(partial_list[0:zero_index[0]])
    for i in range(0, len(zero_index)-1):
        bunkatsu.append(partial_list[zero_index[i]+1:zero_index[i+1]])
    bunkatsu.append(partial_list[zero_index[(len(zero_index)-1)]+1:len(partial_list)])
    print(bunkatsu)
    for i in bunkatsu:
        count += mizuyari(i)
    return count


print(mizuyari(h))


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


def mizuyari(partial_list):
    count = 0
    # print(partial_list)
    if len(partial_list) == 0:
        # print('end return------------ 0 ')
        return 0
    if len(partial_list) == 1:
        # print('end return------' + str(partial_list[0]))
        return partial_list[0]
    
    if min(partial_list) != 0:
        count += min(partial_list)
        # print('count --------' + str(min(partial_list)))
        partial_list = list(map(lambda x: x-min(partial_list), partial_list))
    zero_index = []
    
    for i in range(len(partial_list)):
        if partial_list[i] == 0:
            zero_index.append(i)
    
    bunkatsu = []
    bunkatsu.append(partial_list[0:zero_index[0]])
    for i in range(0, len(zero_index)-1):
        bunkatsu.append(partial_list[zero_index[i]+1:zero_index[i+1]])
    bunkatsu.append(partial_list[zero_index[(len(zero_index)-1)]+1:len(partial_list)])
    
    for i in bunkatsu:
        count += mizuyari(i)
    return count


print(mizuyari(h))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
H = list(map(int, input().split()))




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)
    
    for l, r in segment:
        for i in range(l, r):
            H[i] -= 1
print(ans)

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

stack = [H]
count = 0
while stack:
    lst = stack.pop()
    m = min(lst)
    count += m
    lst = [l-m for l in lst]
    prev = 0
    left = 0
    for i, h in enumerate(lst):
        if h == 0 and prev != 0: 
            stack.append(lst[left:i])
        elif h != 0 and prev == 0:
            left = i
            if i == len(lst)-1: 
                stack.append(lst[left:i+1])
        elif h != 0 and i == len(lst)-1: 
            stack.append(lst[left:i+1])
        prev = h
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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 = test(comb)

print(comb[1])

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

def nextgen(comb):
    lis = comb[0]
    j = comb[1]
    if len(lis) == 1 and lis[0] != 0:
        j += 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])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect


def mizuyari(flowers):
    if flowers == []:
        return 0
    # print(flowers)
    minheight = min(flowers)
    if minheight == 0:
        if max(flowers) == 0:
            return 0
        leftindex = flowers.index(0)
        
        count = mizuyari(flowers[0:leftindex])+mizuyari(flowers[leftindex:])
        return count
    else:
        count = mizuyari([i - minheight for i in flowers]) + minheight
        return count


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

print(mizuyari(h_list))


import bisect


def mizuyari(flowers):
    if flowers == []:
        return 0
    # print(flowers)
    minheight = min(flowers)
    if minheight == 0:
        if max(flowers) == 0:
            return 0
        leftindex = flowers.index(0)
        
        if leftindex == len(flowers):
            count = mizuyari(flowers[0:leftindex])
        else:
            count = mizuyari(flowers[0:leftindex]) + \
                mizuyari(flowers[leftindex+1:])

        return count
    else:
        count = mizuyari([i - minheight for i in flowers]) + minheight
        return count


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

print(mizuyari(h_list))



Verdicts: Runtime Error

Accepted