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
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
hl = LI()
# count = 0

# len_h = len(hl)


#     if n > 0:
#         n = n - 1
#     else:
#         n = 0
#     return n



#     print(0)
#     sys.exit()


#     for j in range(len_h):
#         if j == 0:
#             if hl[j] > 0:
#                 count += 1
#         else:
#             if hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#             elif hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#     hl = list(map(m1, hl))

# print(count)

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



#   1    2    0    0     0

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



import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
hl = LI()
# count = 0

# len_h = len(hl)


#     if n > 0:
#         n = n - 1
#     else:
#         n = 0
#     return n



#     print(0)
#     sys.exit()


#     for j in range(len_h):
#         if j == 0:
#             if hl[j] > 0:
#                 count += 1
#         else:
#             if hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#             elif hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#     hl = list(map(m1, hl))

# print(count)

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



#   1    2    0    0     0

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



import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
hl = LI()
# count = 0

# len_h = len(hl)


#     if n > 0:
#         n = n - 1
#     else:
#         n = 0
#     return n



#     print(0)
#     sys.exit()


#     for j in range(len_h):
#         if j == 0:
#             if hl[j] > 0:
#                 count += 1
#         else:
#             if hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#             elif hl[j] > 0 and hl[j-1] == 0:
#                 count += 1
#     hl = list(map(m1, hl))

# print(count)

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



#   1    2    0    0     0

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



Verdicts: Runtime Error

Runtime Error

Accepted