Problem:


Score : 300 points

Problem Statement

In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0.
You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq  k \leq N), by repeating the following "watering" operation:

Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.

Find the minimum number of watering operations required to satisfy the condition.

Constraints

1 \leq N  \leq 100

0 \leq h_i \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
h_1 h_2 h_3 ...... h_N

Output

Print the minimum number of watering operations required to satisfy the condition.

Sample Input 1

4
1 2 2 1

Sample Output 1

2

The minimum number of watering operations required is 2.
One way to achieve it is:

Perform the operation with (l,r)=(1,3).

Perform the operation with (l,r)=(2,4).

Sample Input 2

5
3 1 2 3 1

Sample Output 2

5

Sample Input 3

8
4 23 75 0 23 96 50 100

Sample Output 3

221



Sample input:
4
1 2 2 1


Sample output:
2

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
f=1
m=max(l)
for j in range(m):
    for i in range(len(l)):
        if i==0:
            f=1
        elif f==0:
            l[i]-=1
        else:
            ans+=1
            l[i]-=1
            f=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
for t in range(len(l)):
    l[t]-=1
ans=1
f=1
m=max(l)
for j in range(m):
    for i in range(len(l)):
        if l[i]==0:
            f=1
        elif f==0:
            l[i]-=1
        else:
            ans+=1
            l[i]-=1
            f=0
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
for t in range(len(l)):
    l[t]-=1
ans=1
f=1
m=max(l)
for j in range(m):
    for i in range(len(l)):
        if l[i]==0:
            f=1
        elif f==0:
            l[i]-=1
        else:
            ans+=1
            l[i]-=1
            f=0
        print(l,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
tmp = 0
f = 0
add = 0
for i in range(n):
    if i == n-1:
        if tmp > a[i]:
            b.append(add)
        else:
            if add < a[i]:
                b.append(a[i]-tmp)
                b.append(add)
            else:
                b.append(add)
        continue
    if tmp > a[i]:
        if f == 0:
            f = 1
        tmp = a[i]
    else:
        if f == 0:
            tmp = a[i]
            add = tmp
        else:
            b.append(add-tmp)
            tmp = a[i]
            add = tmp
            f = 0
# print(b)
print(sum(b))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
tmp = 0
for i in range(n):
    if i == n-1:
        if tmp > a[i]:
            b.append(tmp)
        else:
            b.append(a[i])
        continue
    if tmp > a[i]:
        tmp = tmp - a[i]
        b.append(tmp)
        tmp = 0
    else:
        tmp = a[i]  
print(sum(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

p=max(h)
cnt=[]
ct=0
for i in range(p):
    ct=0
    for j in range(len(h)-1):
        if h[j]==p-i:
            if h[j]==h[j+1]:
                h[j]-=1
                if j==len(h)-2:
                    ct+=1
                    h[j+1]-=1
            else:
                ct+=1
                h[j]-=1
        if j==(len(h)-2):
            if h[j]!=p-i and h[j+1]==p-i:
                h[j+1]-=1
                ct+=1
    cnt.append(ct)
    #print(h,ct)

k=sum(cnt)
print(k)

Submission status: Wrong Answer

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

p=max(h)
cnt=[]
ct=0
for i in range(p):
    ct=0
    for j in range(len(h)-1):
        if h[j]==p-i:
            if h[j]==h[j+1]:
                h[j]-=1
                if j==len(h)-2:
                    ct+=1
                    h[j+1]-=1
            else:
                ct+=1
                h[j]-=1
    cnt.append(ct)
    

k=sum(cnt)
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
# 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
            print(Tree_List)
        ##それ以外は、一緒に処理ができるものがないか確認する
        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)

Submission status: Wrong Answer

Solution code:
# 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)

Submission status: Wrong Answer

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

if N == 1:
    print(arr[0])
    exit()

count =0
while True:
    count +=1
    start = False

    for i in range(N):
        if arr[i] != 0:
            arr[i] -= 1
            start = True
            continue
        if arr[i] == 0 and start == True:
            break
    if sum(arr) == 0:
        break
print(count)

Submission status: Wrong Answer

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

count =0
while True:
    count +=1
    start = False

    for i in range(N):
        if arr[i] != 0:
            arr[i] -= 1
            start = True
            continue
        if arr[i] == 0 and start == True:
            break
    if sum(arr) == 0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
H=list(map(int,input().split()))
m=max(H)
c=m-H[0]
for i in range(1,n):c+=max(H[i-1]-H[i],0)
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split(" ")))
flo = [0]*N
Triger = 0
counter = 0

while True:
  for i in range(N):
    if flo[i] < h[i]:
      for j in range(i,N):
        if flo[j] < h[j]:
          flo[j] += 1
          if j == N-1:
            counter += 1
            Triger += 1
            break
        else:
          counter += 1
          break
      if Triger == 1:
        break
    elif Triger == 1:
      Triger = 0
      break
    else:
      continue
  if h == flo:
    break
print(counter)

Submission status: Wrong Answer

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

counter = 0

while True:
  for i in range(N):
    if flo[i] < h[i]:
      for j in range(i,N):
        if flo[j] < h[j]:
          flo[j] += 1
          if j == N-1:
            counter += 1
        else:
          counter += 1
          break
    else:
      continue
  if h == flo:
    break
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
if sum(h) == 0:
    print(0)
    exit()
ans = 1
last = -1
while True:
    if sum(h) == 0:
        break
    for i in range(N):
        if h[i]:
            h[i] -= 1
            if last != i-1:
                ans += 1
            last = i

    
print(ans)

Submission status: Wrong Answer

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

# check
min_h = min(h)
cnt = min_h
before_idx = 0
for i in range(N):
    if h[i] == min_h or i == N - 1:
        slise_h = h[before_idx:i + 1]
        slise_min = min(slise_h)
        for i, n in enumerate(slise_h):
            if n == slise_min:
                add = n - min_h
            else:
                if i == 0:
                    if slise_h[i + 1] <= n:
                        target = [slise_h[i + 1]]
                    else:
                        target = []
                elif i == len(slise_h) - 1:
                    if slise_h[i - 1] <= n:
                        target = [slise_h[i - 1]]
                    else:
                        target = []
                else:
                    target = [t for t in (slise_h[i - 1], slise_h[i + 1]) if t < n]
                if not target:
                    add = n - slise_min
                else:
                    add = n - max(target)
            cnt += add
            before_h = n
        before_idx = i + 1

print(cnt)

Submission status: Wrong Answer

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

# check
min_h = min(h)
cnt = min_h
before_idx = 0
for i in range(N):
    if h[i] == min_h or i == N - 1:
        slise_h = h[before_idx:i + 1]
        slise_min = min(slise_h)
        for i, n in enumerate(slise_h):
            if n == slise_min:
                add = n - min_h
            else:
                if i == 0:
                    if slise_h[i + 1] <= n:
                        target = [slise_h[i + 1]]
                    else:
                        target = []
                elif i == len(slise_h) - 1:
                    if slise_h[i - 1] <= n:
                        target = [slise_h[i - 1]]
                    else:
                        target = []
                else:
                    target = [t for t in (slise_h[i - 1], slise_h[i + 1]) if t <= n]
                if not target:
                    add = n - slise_min
                else:
                    add = n - max(target)
            cnt += add
            before_h = n
        before_idx = i + 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

h=list(map(int,input().split()))
w=min(h)
h=[i-w for i in h]
ans=w

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
hl = list(map(int, input().split()))
hl.insert(0, 1)

cnt = 0
l = 1
r = n
while True:
    for i in range(1, n + 1):
        if hl[i] >= 1:
            l = i
            break
    for j in range(l, n + 1):
        if hl[j] == 0:
            r = j -1
            break
        if not 0 in hl[l:]:
            r = n
    if l == r:
        hl[l] -= 1
    else:
        for k in range(l, r+1):
            hl[k] -= 1
    cnt += 1
    if sum(hl) == 1:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
hlist = list(map(int, input().split()))
ans = -1
boundary = {0, N-1}
island = 1
dead = set()
for height in range(max(hlist)+1):
    ans += island
    for i in range(N):
        if hlist[i] == height:
            dead.add(i)
            if (i == 0 and 1 in dead) or (i==N-1 and (N-2) in dead) or (i!=0 and i!=(N-1) and (i-1) in dead and (i+1) in dead):
                island -= 1
                continue
            if i not in boundary:
                island += 1
                boundary.add(i-1)
                boundary.add(i+1)
            else:
                if i == 0:
                    boundary.add(1)
                if i == (N-1):
                    boundary.add(N-2)
    # print(height, ans, island, boundary)
print(ans)

Submission status: Wrong Answer

Solution code:
print("H")

Submission status: Wrong Answer

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

ans = 0
while True:
    M = h.index(max(h))
    start = M
    end = M+1
    for i in range(M,-1,-1):
        if h[i] > 0:
            start = i
        else:
            break
    if end != n:
        for i in range(M,n):
            if h[i] > 0:
                end = i+1
            else:
                break
    for i in range(start,end):
        h[i] -= 1
    ans += 1
    if sum(h) <= 0:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
ctr = 0

def mizuyari(left, right, array):
    # left <= x <= right
    N = right - left
    if N == 0:
        global ctr
        ctr += array[left]
    elif N == 1:
        mini = max(array[left], array[right])
        ctr += mini
        if array[left] != 0:
            array[left] -= mini
        else:
            array[right] -= mini
    else:
        mini = 10000
        mini_index = -1
        for i in range(left, right+1):
            if mini > array[i]:
                mini = array[i]
                mini_index = i
        ctr += mini

        for i in range(left, right+1):
            array[i] -= mini

        print(array)
        print(ctr)
        
        if left != mini_index:
            mizuyari(left, mini_index-1, array)
        if mini_index != right:
            mizuyari(mini_index+1, right, array)


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

    mizuyari(0, n-1, h)

solve_C()
print(ctr)

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest
from collections import deque

N = int(input())
heights = tuple(map(int, input().split(' ')))
heights = [h1 for h1, h2 in zip_longest(heights, heights[1:], fillvalue=None) if h1 != h2]

if len(heights) <= 2:
    print(max(heights))
else:
    tops = deque()
    bottoms = deque()

    if heights[0] > heights[1]:
        tops.append(heights[0])

    for i in range(1, len(heights) - 1):
        if heights[i - 1] < heights[i] and heights[i] > heights[i + 1]:
            tops.append(heights[i])
        elif heights[i - 1] > heights[i] and heights[i] < heights[i + 1]:
            bottoms.append(heights[i])

    if heights[-1] > heights[-2]:
        tops.append(heights[-1])

    if len(bottoms) == 0:
        print(tops[0])
    else:
        bottoms.appendleft(bottoms[0])
        bottoms.append(bottoms[-1])

        cost = min(bottoms)
        for index, top in enumerate(tops):
            left = bottoms[index]
            right = bottoms[index + 1]
            cost += top - min(left, right)

        print(cost)

Submission status: Wrong Answer

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    N=pin()
    X=tupin()
    ans=0
    for h in range(101):
        if (X)==[0]*(len(X)):
            print(ans)
            return

        cnt=0
        f=0
        for j in range(len(X)-1):
            if X[j]>0:f=1
            if f and X[j]==0:
                f=0
                cnt+=1
        ans+=(cnt+1)
        #print(X,cnt)

        temp=[]
        for x in X:
            if x>0:
                temp.append(x-1)
            else:temp.append(x)
        X=temp
        #print("".join(X).split("0"))
#%%submit!      
resolve()

Submission status: Wrong Answer

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    N=pin()
    X=tupin()
    ans=0
    for h in range(101):
        if (X)==[0]*(len(X)):
            print(ans)
            return

        cnt=0
        f=0
        for j in range(len(X)-1):
            if X[j]>0:f=1
            if f and X[j]==0 and X[j+1]>0:
                cnt+=1
        ans+=(cnt+1)
        #print(X,cnt)

        temp=[]
        for x in X:
            if x>0:
                temp.append(x-1)
            else:temp.append(x)
        X=temp
#%%submit!      
resolve()

Submission status: Wrong Answer

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
import math
def resolve():
    N=pin()
    X=tupin()
    ans=0
    for h in range(101):
        if (X)==[0]*(len(X)):
            print(ans)
            return

        cnt=0
        for j in range(len(X)-1):
            if X[j]>0 and X[j+1]==0:
                cnt+=1
        ans+=cnt+1
        #print(X,cnt)

        temp=[]
        for x in X:
            if x>0:
                temp.append(x-1)
            else:temp.append(x)
        X=temp
#%%submit!      
resolve()

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10**8)
#N,K=map(int,input().split())
N=int(input())
h=np.array(list(map(int,input().split())))
ans=0
def sol(l,m,k):
    global ans
    if m==0:
        return ans
    elif m>1:
        for i in range(N-m+1):
            if not 0 in l[i:i+m]:
                ans+=np.amin(l[i:i+m])
                l[i:i+m]=l[i:i+m]-min(l[i:i+m])
                #print(l)
        sol(l,m-1,ans)
    else:
        ans+=np.count_nonzero(h)
        sol(l, m - 1, ans)
n=0
sol(h,N,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10**6)
#N,K=map(int,input().split())
N=int(input())
h=np.array(list(map(int,input().split())))
ans=0
def sol(l,m,k):
    global ans
    if m==0:
        return ans
    elif m>1:
        for i in range(N-m+2):
            if not 0 in l[i:i+m-1]:
                ans+=np.amin(l[i:i+m-1])
                l[i:i+m-1]-=np.amin(l[i:i+m-1])
        sol(l,m-1,ans)
    else:
        ans+=np.count_nonzero(h)
        sol(l, m - 1, ans)
n=0
sol(h,N,ans)
print(ans)

Submission status: Wrong Answer

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

ans = 0
while any(H):
    water = min(h for h in H if h)
    cnt = 0
    for x, y in zip(H[:-1], H[1:]):
        if x > y and y == 0:
            cnt += 1
        elif x < y and x == 0:
            cnt += 1
    ans += water * (cnt // 2 + 1)
    H = [max(0, h-water) for h in H]


print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

match = "keyence"
check = ""
revcheck = ""

flag = False

for x in range(len(S)):
    if x == len(match):
        break
    if match[x] == S[x]:
        check += S[x]
    else:
        flag = True
        break

if flag:
    revS = "".join(reversed(S))
    revMatch = "".join(reversed(match))
    for y in range(len(revS)):
        # print(revS[y])
        if y == len(revMatch):
            break
        if revMatch[y] == revS[y]:
            revcheck += revS[y]
        else:
            break

    finalCheck = check + "".join(reversed(revcheck))
    if finalCheck == match:
        print("YES")
    else:
        print("NO")
elif check == match:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

nh = []
pre = -1
for i in range(N):
    if pre != h[i]:
        nh.append(h[i])
    pre = h[i]
    
ans = 0
for i in range(max(nh)):
    for j in range(len(nh)):
        nh[j] -= 1
        if nh[j] < 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = min(h)
h_ = [n - ans for n in h] + [0]
j = -1
while max(h_) > 0:
    for i, n in enumerate(h_):
        if n == 0:
            if (j + 1) < i:
                m = min(h_[j+1:i])
                ans += m
                for k in range(j+1, i):
                    h_[k] = h_[k] - m
            j = i
    print(h_)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys 
sys.setrecursionlimit(1000)
n=int(input())
H=list(map(int,input().split()))
def bunkai(H):
    B=[]
    b=0
    f=0
    for i in range(len(H)):
        if H[i]==0:
            if i!=0:
                B.append(H[b:i-1+1])
                b=i+1
            else:
                b=i+1
        elif i==len(H)-1:
            B.append(H[b:])
    return B
def min(lis):
    min=999999999999999
    for i in range(len(lis)):
        if lis[i]<min:
            min=lis[i]
    return min
def mizu(lis,n):
    for i in range(len(lis)):
        lis[i]+=-n
    return lis
def sso(lis,sum):
    #print(sum)
    B=bunkai(lis)
    #print(B)
    if len(B)==0:
        #print("return: "+str(sum))
        return sum
    for l in B:
        #print(l)
        x=min(l)
        sum+=x
        li=mizu(l,x)
        sum=sso(li,sum)
    #print("return end:"+str(sum))
    return sum


sum=0
x=sso(H,sum)

    
print(x)

Submission status: Wrong Answer

Solution code:
import sys 
sys.setrecursionlimit(1000)
n=int(input())
H=list(map(int,input().split()))
def bunkai(H):
    B=[]
    b=0
    f=0
    for i in range(len(H)):
        if H[i]==0:
            if i!=0:
                B.append(H[b:i-1+1])
                b=i+1
            else:
                b=i+1
        elif i==len(H)-1:
            B.append(H[b:])
    return B
def min(lis):
    min=999999999999999
    for i in range(len(lis)):
        if lis[i]<min:
            min=lis[i]
    return min
def mizu(lis,n):
    for i in range(len(lis)):
        lis[i]+=-n
    return lis
def sso(lis,sum):
    #print(sum)
    B=bunkai(lis)
    #print(B)
    if len(B)==0:
        #print("return: "+str(sum))
        return sum
    for l in B:
        #print(l)
        x=min(l)
        sum+=x
        li=mizu(l,x)
        sum=sso(li,sum)
    #print("return end:"+str(sum))
    return sum


sum=0
x=sso(H,sum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
List = list(map(int, input().split()))

ans=0

L=0
while 1==1:
    R=L

    #終了判断
    if sum(List)==0:
        break
    elif R==len(List)-1:
        #リストの端の時
        List[R]=List[R]-1
        ans+=1
        #print("処理1")
    elif List[L]>List[L+1]:
        List[L]=List[L]-1
        #回数
        ans+=1
        #print("処理2")
    else:
        checkMAX=1
        while 1==1:
            #print("マックスの表示")
            #print(checkMAX)
            
            R+=1
            if R==len(List)-1:
                #範囲が決まったとき
                for i in range(L,R+1):#R+1追加あああああああ
                    List[i]=List[i]-1
                #回数
                ans+=1
                #print("処理3")
                break
            elif checkMAX>List[R+1]:
                #print("次の数")
                #print(List[R+1])
                #範囲が決まったとき
                for i in range(L,R+1):#R+1追加あああああああ
                    List[i]=List[i]-1
                #回数
                ans+=1
                #print("処理4")
                break
            else:
                checkMAX=List[R+1]
                pass
            
    #デバッグ
    #print("Lを表示")
    #print(L)
    #print(List)
            
    #print(ans)
    if sum(List)!=0 and List[L]==0:
        while List[L]==0:
            L+=1
    #L+=1
print(ans)

Submission status: Wrong Answer

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

while min(h) != 0:
    h = list(map(lambda x: x-1,h))
    ans += 1

while sum(h) != 0:
    flag = False
    for i in range(n):
        if i == n-1:
            h[i] -= 1
            ans += 1
        elif h[i] == 0 and flag:
            ans += 1
            break
        elif h[i] != 0:
            h[i] -= 1
            flag = True
else:
    print(ans)

Submission status: Wrong Answer

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

while min(h) != 0:
    h = list(map(lambda x: x-1,h))
    ans += 1

while sum(h) != 0:
    flag = False
    for i in range(n):
        if i == n-1:
            h[i] -= 1
            ans += 1
            break
        if h[i] == 0 and flag:
            ans += 1
            break
        elif h[i] != 0:
            h[i] -= 1
            flag = True
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
if n == 1 and L[0]:
    print(1)
    exit()

h = L[0]
cnt = 0
for i in range(n-1):
    if L[i] < L[i+1]:
        h += L[i+1] - L[i]
        if i+1 == n-1:
            cnt +=h
    elif L[i] >= L[i+1]:
        cnt +=h
        h = 0

print(cnt)

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
res = 0
perfect = [0]*N
while h != perfect:
    i = 0
    while h[i] == 0:
        i += 1
    l = i
    while h[i] != 0:
        if i == N-1:
            i = N
            break
        i += 1
    r = i-1
    if l == r:
        min_n = h[l]
    else:
        min_n = min(h[l:r])
    res += min_n
    for j in range(l,r+1):
        h[j] -= min_n
print(res)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
N = int(input())

H = list(map(lambda x: int(x) + 1, input().split()))

def it(items, count):
    if not items:
        return 0
    if len(items) == 1:
        return items[0] + count

    ids = [-1]
    for i in range(len(items)):
        items[i] -= 1
        if items[i] <= 0:
            ids.append(i)
    ids.append(len(items))

    ans = 0
    for i in range(len(ids)-1):
        next_items = items[ids[i]+1:ids[i+1]]
        ans += it(next_items, count+1)
        if next_items:
            count = -1

    return ans

print(it(H, -1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

N = int(input())

H = list(map(lambda x: int(x) + 1, input().split()))

def it(items, count):
    if not items:
        return 0
    if len(items) == 1:
        return items[0] + count

    ids = [-1]
    for i in range(len(items)):
        items[i] -= 1
        if items[i] <= 0:
            ids.append(i)
    ids.append(len(items))

    ans = 0
    for i in range(len(ids)-1):
        next_items = items[ids[i]+1:ids[i+1]]
        ans += it(next_items, count+1)
        if next_items:
            count = -1

    return ans

print(it(H, -1))

Submission status: Wrong Answer

Solution code:
n = int(input())
h = [int(i) for i in input().split()]
def cnt_ope(h):
    diff_h = [h[i + 1] - h[i] for i in range(len(h) - 1)]
    ext_h = [0] * (len(diff_h) - 1)
    for i in range(len(diff_h) - 1):
        if diff_h[i] < 0 and diff_h[i + 1] > 0:
            ext_h[i] = -1
    try:
        ext_i = ext_h.index(-1) + 1
        return (cnt_ope(h[:ext_i]) - h[ext_i]) + (cnt_ope(h[ext_i + 1:]) - h[ext_i]) + h[ext_i]
    except ValueError:
        return max(h)
print(cnt_ope(h))

Submission status: Wrong Answer

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

kyokusyou = 0
count = 0
gezan = False
for i in range(n):
  if a[i+1] < a[i]:
    count += a[i] - kyokusyou
    gezan = True
  if gezan and a[i+1] > a[i]:
    gezan = False
    kyokusyou = a[i]
print(count)

Submission status: Wrong Answer

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

f = [0] * n
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
now = [0]*n
ans = 0

while li != now:
    x = 0
    for i in range(n):
        if now[i] < li[i]:
            now[i] += 1
            x = 1
        elif now[i] == li[i] and x == 1 and i != n-1:
            ans += 1
            x = 0
    ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
h.sort()
h.reverse()
max=h[0]
sum=0
for i in range(n):
    if max!=h[i]:
        sum=sum+max-h[i]
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
h.sort()
max=h[0]
sum=0
for i in range(n):
    if max!=h[i]:
        sum=sum+max-h[i]
print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
H=list(map(int,input().split()))
m=0
ans=0
i=1
while i<N:
  while i<N and H[i]>=H[i-1]:
    i+=1
  ans+=H[i-1]-m
  while i<N and H[i]<=H[i-1]:
    i+=1
  m=H[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int, input().split()))
counter = 0
fin = [0 for _ in range(N)]

while not h == fin:
    for i in range(1, N-1):
        if h[i] == 0 and not h[i-1] == 0:
            counter += 1
    counter += 1
    for i in range(N):
        if not h[i] == 0:
            h[i] -= 1


print(counter)