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):
def countA(A):
    global cnt
    if len(A)==1:
        cnt += A[0]
    else:
        amin = min(A)
        A = [A[i]-amin for i in range(len(A))]
        cnt += amin
        while A:
            if A[0]==0:
                A.pop(0)
            elif A[-1]==0:
                A.pop()
            else:break
        B = []
        for i in range(1,len(A)):
            if A[i]==0 and A[i-1]==0:
                B.append(i)
        C = []
        for i in range(len(A)):
            if i not in B:
                C.append(A[i])
        C0 = []
        for i in range(len(C)):
            if C[i]==0:
                C0.append(i)
        if len(C0)==0 and len(C)>0:
            countA(C)
        else:
            cur = 0
            for c in C0:
                countA(C[cur:c])
                cur = c+1
            countA(C[cur:])
            
N = int(input())
H = list(map(int,input().split()))
cnt = 0
countA(H)
print(cnt)

def countA(A):
    global cnt
    if len(A)==1:
        cnt += A[0]
    else:
        amin = min(A)
        A = [A[i]-amin for i in range(len(A))]
        cnt += amin
        while A:
            if A[0]==0:
                A.pop(0)
            elif A[-1]==0:
                A.pop()
            else:break
        B = []
        for i in range(1,len(A)):
            if A[i]==0 and A[i-1]==0:
                B.append(i)
        C = []
        for i in range(len(A)):
            if i not in B:
                C.append(A[i])
        C0 = []
        for i in range(len(C)):
            if C[i]==0:
                C0.append(i)
        if len(C0)==0 and len(C)>0:
            countA(C)
        else:
            cur = 0
            for c in C0:
                countA(C[cur:c])
                cur = c+1
            if cur<len(C):
                countA(C[cur:])
            
N = int(input())
H = list(map(int,input().split()))
cnt = 0
countA(H)
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):
import sys
L = int(sys.stdin.readline().rstrip())

if L == 1:
  h = int(sys.stdin.readline().rstrip())
else:
  h = list(map(int, sys.stdin.readline().rstrip().split()))

L = N
if L == 0:
  ans = 0
elif L == 1:
  ans = N - h
elif L == 2:
  ans = N - max(h)
  
else:
  grad1 = h[0] > h[1]
  p= 0
  v= 0
  if grad1:
    p += h[0]

  for n in range(2, L):
    grad2 = h[n-1] > h[n] 
    if grad1 == grad2:
      continue
    elif grad2:
      p += h[n-1]
    else:
      v += h[n-1]
    grad1 = grad2
               
  if not grad1:
    p += h[n]
 
ans = p - v
print(ans)

N = int(sys.stdin.readline().rstrip())
h = map(int, sys.stdin.readline().rstrip().split())

L = len(h)
if L == 0:
  ans = 0
elif L < 1:
  ans = N - h[0]
elif L < 2:
  ans = N - max(h)
  
else:
  grad1 = h[0] > h[1]
  if grad1:
    p = [h[0]]
  else:
    p = []
    
  v = []
  for n in range(2, L):
    grad2 = h[n-1] > h[n] 
    if grad1 == grad2:
      continue
    elif grad2:
      p.append(h[n-1])
    else:
      v.append(h[n-1])
    grad1 = grad2
               
  if not grad1:
    p.append(h[n])
 
ans = sum(p) - sum(v)
print(ans)

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

Verdicts: 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()) + 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)





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(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 = [int(input()) for _ in range(N)]
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)
    

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)
    

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=[0]+list(map(int,input().split()))
c=0
for i in range(N):
  c+=max(h[i+1]-l[i],0)
print(c)

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

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

for i in range(max(h)):
    st = 1 if h[0] != 0 else 0
    for j in range(n):
        if st == 1:
            if h[j] == 0:
                cnt += 1
                st = 0
            else:
                h[j] -= 1
        else:
            if h[j] != 0:
                st = 1
                h[j] -= 1
    else:
        if st == 1:
            cnt += 1
else:
    ans = cnt

n = int(input())
h = [int(i) for i in input().split()]
ans = h[0]
for i in range(1,n): ans += max(0,h[i]-h[i-1])
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
check = 0
print(len(h))
for i in h:
    if check < i:
        ans += i-check
    check = i

print(ans)


n = int(input())
h = list(map(int, input().split()))
ans = 0
cheak = 0
if n == 1:
    ans += h[0]    
elif n != 0:
    for i in range(1, n-1):
        if h[i-1] > h[i] and h[i+1] > h[i]:
            cheak += h[i]
        elif h[i-1] < h[i] and h[i+1] < h[i]:
            ans += h[i]

    if h[n-1] >= h[n-2]:
        ans += h[n-1]
ans -= cheak
print(ans)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *h = map(int, read().split())
ans = h[0]
for bf, af in zip(h, h[1:]):
    if af > bf:
        ans += af - bf
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):
n = int(input())
h = input().split()

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

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

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):
s = int(input())
a = list(map(int, input().split()))

incFlg = True   
before_height = 0
sum = 0

for i in range(len(a)-1):
    
    if a[i] > a[i+1]:
        
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        
        else:
            # before_height = a[i]
    
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True

if incFlg:
    sum += a[len(a)-1] - before_height

print(sum)


s = int(input())
a = list(map(int, input().split()))

incFlg = True   
before_height = 0
sum = 0

for i in range(len(a)-1):
    
    if a[i] > a[i+1]:
        
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        
        # else:
        #     # before_height = a[i]
    
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True

if incFlg:
    sum += a[len(a)-1] - before_height

print(sum)


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):
num = int(input())
targets = map(int, input().split())
targets = list(targets)


water_cnt = 0
def exe_water(init_state):
    # break condition
    if sum(init_state) == 0:
        return
    temp_water_cnt = min(init_state)
    water_cnt += temp_water_cnt

    lowest = temp_water_cnt
    # init sub_state
    sub_state = []
    for h in init_state:
        substracted_h = h - lowest
        if substracted_h != 0:
            sub_state.append(substracted_h)
        else:
            exe_water(sub_state)
            
            sub_state = []

exe_water(targets)
print(water_cnt)


num = int(input())
targets = map(int, input().split())
targets = list(targets)


global water_cnt
water_cnt = 0
def exe_water(init_state):
    global water_cnt
    # break condition
    if sum(init_state) == 0:
        return
    temp_water_cnt = min(init_state)
    water_cnt += temp_water_cnt

    lowest = temp_water_cnt
    # init sub_state
    sub_state = []
    for h in init_state:
        substracted_h = h - lowest
        if substracted_h != 0:
            sub_state.append(substracted_h)
        else:
            exe_water(sub_state)
            
            sub_state = []
    # end case where no trailing 0
    exe_water(sub_state)

exe_water(targets)
print(water_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):
import sys
sys.setrecursionlimit(1000000)
def watering(l,a,b):
  if b-a <= 1:
    return l[a]
  
  c = 0
  t = a
  
  mi = min(l[a:b])
  for i in range(a,b):
    l[i] -= mi
    
  for i in range(a,b):
    if l[i]==0:
      c += watering(l,t,i)
      t=i+1
  c += watering(l,t,b)
      
  return c+mi

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

print(watering(h,0,n))

import sys
sys.setrecursionlimit(1000000)
def watering(l,a,b):
  if b==a:
    return 0
  if b-a <= 1:
    return l[a]
  
  c = 0
  t = a
  
  mi = min(l[a:b])
  for i in range(a,b):
    l[i] -= mi
    
  for i in range(a,b):
    if l[i]==0:
      c += watering(l,t,i)
      t=i+1
  c += watering(l,t,b)
      
  return c+mi

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

print(watering(h,0,n))

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):
import sys
import copy
N=int(input())
H = [int(x) for x in input().split()]

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

cnt=0
while True:
    f=True
    for h in H:
        if h!=0:
            f=False
            break
    if f:
        break

    H_new = copy.copy(H)
    if H[0]!=0 and H[1]==0:
        cnt+=1
        H_new[0]-=1
    for i in range(1,len(H)):
        if H[i-1]==0 and H[i]!=0:
            cnt+=1
        if H_new[i]!=0:
            H_new[i]-=1
    H = copy.copy(H_new)


print(cnt)


import sys
import copy
N=int(input())
H = [int(x) for x in input().split()]

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

cnt=0
while True:
    f=True
    for h in H:
        if h!=0:
            f=False
            break
    if f:
        break

    H_new = copy.copy(H)
    if H[0]!=0:
        if H[0]!=0:
            cnt+=1
        H_new[0]-=1
    for i in range(1,len(H)):
        if H[i-1]==0 and H[i]!=0:
            cnt+=1
        if H_new[i]!=0:
            H_new[i]-=1
    H = copy.copy(H_new)


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):
from math import factorial
from sys import exit, stdin
N = int(stdin.readline().rstrip())
H = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(1,n):
    if H[i-1] > H[i]:
        ans += H[i-1]-H[i]
ans += H[-1]
print(ans)

from math import factorial
from sys import exit, stdin
N = int(stdin.readline().rstrip())
H = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(1,N):
    if H[i-1] > H[i]:
        ans += H[i-1]-H[i]
ans += H[-1]
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):
N = int(input())
height = list(map(int, input().split())) 
water_count = 0 
while True:
    index = [i for i, v in enumerate(height) if v >0] 
    
    
    min_index = index[0] 
    max_index = index[0] 
    
    while True:
        if max_index+1 in index:
            max_index += 1
        else:
            break
            
    # print("index: {}".format(index)) 
    
    water_amount = min(height[min_index:max_index+1]) 
    for flower in range(min_index, max_index+1):
        height[flower] -= water_amount 
    
    # print("height:{} ".format(height))
    water_count +=water_amount
        
    if np.sum(height) ==0: 
        break
print(water_count)

N = int(input()) 
height = list(map(int, input().split())) 
water_count = 0 
while True:
    index = [i for i, v in enumerate(height) if v >0] 
    
    if len(index) == len(height): 
        height -= 1 
        water_count += 1
    
    else:
        
        min_index = index[0] 
        max_index = index[0] 
    
        while True:
            if (max_index+1) in index:
                max_index += 1
            else:
                break
    
        for flower in range(min_index, max_index+1):
            height[flower] -= 1 
        water_count += 1 
        
    if sum(height) == 0: 
        break
print(water_count)

def solve(height):
    
    water_count = 0 

    while True:
        index = [i for i, v in enumerate(height) if v >0] 
    
        
        min_index = index[0] 
        max_index = index[0] 
    
        while True:
            if (max_index+1) in index:
                max_index += 1
            else:
                break
    
        for flower in range(min_index, max_index+1):
            height[flower] -= 1 
        water_count += 1 
        
        if sum(height) == 0: 
            break
    print(water_count)
    
def solve_zero(height): 
    print(0)

if __name__ == "__main__":
    N = int(input()) 
    height = list(map(int, input().split())) 
    if sum(height) == 0:
        solve_zero(height)
    else:
        solve(height)

Verdicts: 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()))
ans = 0
active = 0
for i in range(N):
    h = H[i]
    ans += min(0, h - active)
    active = h
print(ans)


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


N = int(input())
H = list(map(int, input().split()))
ans = H[0]
active = H[0]
for i in range(1,N):
    h = H[i]
    ans += max(0, h - active)
    active = h
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):
N = map(int, input().split())
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)

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

count = 0

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

count = count + h[N-1]

print(count)

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 = int()
for i in reversed(range(1, max(h)+1)):
    tmp = list()
    for j in h:
        if i <= j:
            tmp.append(1)
        else:
            tmp.append(0)
    # print(tmp)
    for j in range(1, n):
        if tmp[j]-tmp[j-1] == 1:
            cnt += 1

print(cnt)


n = int(input())
h = list(map(int, input().split()))
cnt = int()
for i in reversed(range(1, max(h)+1)):
    tmp = list()
    for j in h:
        if i <= j:
            tmp.append(1)
        else:
            tmp.append(0)
    #print(tmp)
    if tmp[0]==1:
        cnt += 1
    for j in range(1, n):
        if tmp[j]-tmp[j-1] == 1:
            cnt += 1

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


N = int(input())
hlist = list(map(int, input().split()))
def count_island(height):
    res = 0
    sink = True
    for h in hlist:
        if sink and h > height:
            res += 1
            sink = False
        if h <= height:
            sink = True
    return res

ans = 0
for height in range(max(hlist)):
    ans += count_island(height)
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()))

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

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

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

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 = input()
str_h = input()

fls = flowers(str_h)
ls_fls = fls.str_split0()
water = 0

while(len(ls_fls)>0):
    #print(f'ls_fls = {ls_fls}')
    temp_ls_fls = []
    for fls in ls_fls:
        if len(fls)<=2:
            water += max([int(s) for s in fls])
            continue
        else:
            _fls = flowers(' '.join(fls))
            _fls.minimize()
            _ls_fls = _fls.str_split0()
            water += _fls.water
            temp_ls_fls += _ls_fls
            flg=1
    ls_fls = temp_ls_fls
print(water)

class flowers:
    def __init__(self, str_h):
        self.str = str_h.split()
        self.int = []
        self.min = 0
        self.water = 0
        
        self.update_int()
        self.update_min()
    
    def update_str(self):
        self.str = list(map(str, self.int))
        return

    def update_int(self):
        self.int = list(map(int, self.str))
        return
    
    def update_min(self):
        self.min = min(self.int)
        return
    
    def minimize(self):
        self.int = [n-self.min for n in self.int]
        self.water += self.min
        self.update_str()
        self.min = 0
        return
    
    def str_split0(self):
        idxs = [-1] + [i for i,n in enumerate(self.int) if n==0]
        if len(idxs)==1:
            return [self.str]
        else:
            temp_ls = []
            for i in range(len(idxs)-1):
                s = self.str[idxs[i]+1:idxs[i+1]]
                if len(s)>0: temp_ls.append(s)
            if self.int[-1]!=0:
                temp_ls.append(self.str[idxs[-1]+1:])
        return temp_ls

N = input()
str_h = input()

fls = flowers(str_h)
ls_fls = fls.str_split0()
water = 0

while(len(ls_fls)>0):
    #print(f'ls_fls = {ls_fls}')
    temp_ls_fls = []
    for fls in ls_fls:
        if len(fls)<=2:
            water += max([int(s) for s in fls])
            continue
        else:
            _fls = flowers(' '.join(fls))
            _fls.minimize()
            _ls_fls = _fls.str_split0()
            water += _fls.water
            temp_ls_fls += _ls_fls
            flg=1
    ls_fls = temp_ls_fls
print(water)


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):
# https://atcoder.jp/contests/abc116/tasks/abc116_c C - Grand Garden
n=int(input())
Tree_List=list(map(int,input().split()))

ct =0
for i in range(n):
    while Tree_List[i] != 0:
        
        if i == n-1:
            Tree_List[i] -= 1
        
        else:
            
            k=i+1
            while Tree_List[k] != 0 and k < n-1: 
                k += 1
            Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])
        
        ct += 1

        
print(ct)

# https://atcoder.jp/contests/abc116/tasks/abc116_c C - Grand Garden
n=int(input())
Tree_List=list(map(int,input().split()))

ct =0
for i in range(n):
    while Tree_List[i] != 0:
        
        if i == n-1:
            Tree_List[i] -= 1
        
        else:
            
            k = i + 1
            while Tree_List[k] != 0: 
                k+=1
                if k == n:
                    break
            Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])
        
        ct += 1
        
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):
n = int(input())
c, *lst = [int(i) for i in input().split()]
for i in range(1, n):
  if lst[i] > lst[i - 1]:
      c += lst[i] - lst[i - 1]
print(c)

n = int(input())
lst = [int(i) for i in input().split()]
c = lst[0]
for i in range(1, n):
  if lst[i] > lst[i - 1]:
      c += lst[i] - lst[i - 1]
print(c)

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 = list(map(int, input().split())) + [0]
ans = 0
min_v = 101
curr = 0
last = -1
count = 0

for _ in range(n+1):
    for i in range(n+1):
        curr = l[i]
        if curr == 0:
            for j in range(last+1, i):
                l[j] -= min_v

            if i > last + 1:
                count += min_v

            last = i
            min_v = 101
            curr = 0
        elif curr < min_v:
            min_v = curr
        print(l)
    last = -1

print(count)





n = int(input())
l = list(map(int, input().split())) + [0]
ans = 0
min_v = 1000
curr = 0
last = -1
count = 0

for _ in range(n+1):
    for i in range(n+1):
        curr = l[i]
        if curr == 0:
            for j in range(last+1, i):
                l[j] -= min_v

            if i > last + 1:
                count += min_v

            last = i
            min_v = 1000
            curr = 0
        elif curr < min_v:
            min_v = curr
    last = -1

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())
listh = list(map(int, input().split()))
listans = [listh[0]]
for n in range(1,N-1):
    if (listh[n+1]-listh[n])*(listh[n]-listh[n-1])<=0:
        listans.append(listh[n])
listans.append(listh[N-1])        
#print(listans)
l =len(listans)
listans2 = []
for n in range(l-1):
    if listans[n] == listans[n+1]:
        pass
    else:
        listans2.append(listans[n])
listans2.append(listans[l-1])        
#print(listans2)    
L = len(listans2)
#print(L)
listodd = [listans2[x] for x in range(L) if x%2 ==1]
#print(listodd)
listeven = [listans2[x] for x in range(L) if x%2 ==0]

if L%2 == 0:
    if listeven[0]>listodd[0]:
        del listodd[-1]
        ans = sum(listeven)-sum(listodd)
        print(ans)

    else:  
        del listeven[0]
        ans = sum(listodd)-sum(listeven)  
        print(ans)

else:     
    if listeven[0]>listodd[0]:
        ans = sum(listeven)-sum(listodd)
        print(ans)

    else:
        del listeven[-1]
        if len(listeven)>0
        del listeven[0]
        ans = sum(listodd)-sum(listeven)
        print(ans)
        

N = int(input())
listh = list(map(int, input().split()))
listans = [listh[0]]
for n in range(1,N-1):
    if (listh[n+1]-listh[n])*(listh[n]-listh[n-1])<=0:
        listans.append(listh[n])
listans.append(listh[N-1])        
#print(listans)
l =len(listans)
listans2 = []
for n in range(l-1):
    if listans[n] == listans[n+1]:
        pass
    else:
        listans2.append(listans[n])
listans2.append(listans[l-1])        
#print(listans2)    
L = len(listans2)
#print(L)
listans3 = [listans2[0]]
for n in range(1,L-1):
    if (listans2[n+1]-listans2[n])*(listans2[n]-listans2[n-1])<=0:
        listans3.append(listans2[n])
listans3.append(listans2[L-1])        
#print(listans3)
ll =len(listans3)
listodd = [listans3[x] for x in range(ll) if x%2 ==1]
#print(listodd)
listeven = [listans3[x] for x in range(ll) if x%2 ==0]

if len(listodd) == 0:
    print(listeven[0])
elif ll%2 == 0:
    if listeven[0]>listodd[0]:
        del listodd[-1]
        ans = sum(listeven)-sum(listodd)
        print(ans)

    else:  
        del listeven[0]
        ans = sum(listodd)-sum(listeven)  
        print(ans)

else:     
    if listeven[0]>listodd[0]:
        ans = sum(listeven)-sum(listodd)
        print(ans)

    else:
        del listeven[-1]
        if len(listeven) >= 1:
            del listeven[0]
        ans = sum(listodd)-sum(listeven)
        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):
n=int(input())
h=list(map(int,input().split()))
ans=0

def f(li):
  global ans
  
  
  if li==[]:
    del li
    return
  
  
  min_num=min(li)
  if min(li)>0:
    count+=min(li)
    li=list(map(lambda x: x-min(li), li))
  li=[li[:li.index(0)],li[li.index(0)+1:]]
  f(li[0])
  f(li[1])

f(h)
print(count)

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

def f(li):
  global ans
  
  
  if li==[]:
    del li
    return
  
  
  min_num=min(li)
  if min(li)>0:
    ans+=min(li)
    li=list(map(lambda x: x-min(li), li))
  li=[li[:li.index(0)],li[li.index(0)+1:]]
  f(li[0])
  f(li[1])

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

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1
    print(h_ls)

print(n)


N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1

print(n)


import numpy as np

N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1

print(n)


Verdicts: 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=ini(input())
h=[int(i) for i input().split()]
j=0
ans=0
while True:
  if h[0]>j:
    ans+=1
  for i in range(1,n):
    if h[i-1]<=j and h [i]>j:
      ans+=1
  j+=1
  if j==max(h):
    break
print(ans) 

n=int(input())
h=[int(i) for i input().split()]
j=0
ans=0
while True:
  if h[0]>j:
    ans+=1
  for i in range(1,n):
    if h[i-1]<=j and h [i]>j:
      ans+=1
  j+=1
  if j==max(h):
    break
print(ans) 

n=int(input())
h=[int(i) for i in input().split()]
j=0
ans=0
while j<max(h):
  if h[0]>j:
    ans+=1
  for i in range(1,n):
    if h[i-1]<=j and h [i]>j:
      ans+=1
  j+=1
print(ans) 

Verdicts: 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):
import numpy as np

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

h = np.array(h)

count = 0
while(sum(h) != 0):
    s = 200
    e = n
    for i in range(n):
        if(s == 200):
            if(h[i] != 0): s = i
        elif(h[i] == 0):
            e = i
            break

    count += min(h[s:e])
    h[s:e] -= min(h[s:e])

    print(h)

print(count)

import numpy as np

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

h = np.array(h)

count = 0
while(sum(h) != 0):
    s = 200
    e = n
    for i in range(n):
        if(s == 200):
            if(h[i] != 0): s = i
        elif(h[i] == 0):
            e = i
            break

    count += min(h[s:e])
    h[s:e] -= min(h[s:e])

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())
l=[int(i) for i in input().split()]
v=sum(l)
e=0
for i in range(max(l)):
  ef=0
  for j in l:
    print(i,j)
    if j>i:
      ef+=1
    else:
      if ef>0:
        e+=ef-1
      ef=0
  if ef>1:
    e+=ef-1
print(v-e)


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


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 = input()
h = 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)

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)

import numpy as np
N = 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)

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

# N =  8
# h = np.array(list(map(int, "4 23 75 0 23 96 50 100".split())))

a = np.zeros(N)
h_min = min(h)
h_max = max(h)
n_loop = h_max - h_min

cnt = 0
for zzz in range(n_loop):
    tmp = (h >= h_min+1+zzz)*1
#     print(tmp)
    for idx, i in enumerate(tmp):
        if idx==0:
            first = i
            a0 = i
            continue
            
        if i==a0:
            continue
        else:
            if i==1:
                cnt+=1
            a0 = i
    else:
        if first==1:
            cnt+=1
            
print(cnt+h_min)

Verdicts: Runtime Error

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


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

ans = 0

while len(L) :
    if L[0] == 0 :
        L.pop(0)
    else :
        ans += 1
        for i in range(len(L)) :
            if L[i] != 0 :
                L[i] -= 1
            else :
                break
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):
le = int(input())
ll=list(map(int, input().split(' ')))


res=0

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

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted