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

Submission status: Wrong Answer

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

ans = 0
h_list.append(0)
while True:
    idx_left = 0
    idx_right = None
    for i in range(N):
        if h_list[i] == 0 and h_list[i+1] != 0:
            idx_left = i+1
        if h_list[i] != 0 and h_list[i+1] == 0:
            idx_right = i

        if idx_right is not None:
            if idx_right == idx_left:
                pour = h_list[idx_left]
                ans += pour
                h_list[idx_left] = 0
            else:
                pour = min(h_list[idx_left:idx_right])
                for j in range(idx_right - idx_left + 1):
                    h_list[idx_left+j] = h_list[idx_left+j] - pour
                ans += pour
            break

    if all([h == 0 for h in h_list]):
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
counter = 0
while h:
    if not 0 in h:
        for i,j in enumerate(h):
            j -= 1
            h[i] = j
        counter+=1     
    else:
        ind = h.index(0)
        if not ind == 0:
            plcs = h[:ind]
            counter += max(plcs)         
        #処理後に0と処理したものを削除
        h = h[ind+1:]
            
              
    #print(h)
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
counter = 0
while h:
    if 0 in h:
        ind = h.index(0)
        if ind == 0:
            ind = 1
        plcs = h[:ind]
        counter += max(plcs)         
        #処理後に0と処理したものを削除
        h = h[ind+1:]        
    else:
        for i,j in enumerate(h):
            j -= 1
            h[i] = j
        counter+=1        
    # print(h)
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
counter = 0
while h:
    if 0 in h:
        ind = h.index(0)
        if ind == 0:
            ind = 1
        plcs = h[:ind]
        counter += max(plcs)         
        #処理後に0と処理したものを削除
        h = h[ind+1:]        
    else:
        for i,j in enumerate(h):
            j -= 1
            h[i] = j
        counter+=1        
    print(h)
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

v = list(map(int, input().split()))

def dfs(l, r):
  if l == r:
    return 0
  m = 100
  for i in range(l, r):
    m = min(m, v[i])
  if m == 0:
    return 0
  res = 0
  for i in range(l, r):
    v[i] -= m
  last = 0
  for i in range(l, r):
    if v[i] == 0:
      res += dfs(last, i)
      last = i + 1
  return res
print(dfs(0, n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
d = np.diff(H)

ra = []
m = []
for i in range(len(d) - 1):
    if d[i] < 0 and d[i + 1] > 0:
        ra.append(i + 1)
        m.append(H[i + 1])

ra = [0] + ra + [N]
M = []
for i in range(len(ra) - 1):
    M.append(np.max(H[ra[i]:ra[i + 1]]))

print(sum(M) - sum(m))

Submission status: Wrong Answer

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

cnt=0
for i in range(max(H)):#O(N)
    flg=0
    for j in range(N):#O(N^2)
        if flg==0:
            if H[j]!=0:
                H[j]-=1
                cnt+=1
                flg=1
            else:
                flg=0
        else:
            if H[j]!=0:
                H[j]-=1
            #else:
             #   flg=0
print(cnt)
#O(N^2),N==100で余裕

Submission status: Wrong Answer

Solution code:
N = int(input())
H = list(map(int,input().split()))
H = [0]+H+[0]
def trm(H):
  for i in range(len(H)-2,0,-1):
    if H[i-1]<=H[i]<=H[i+1]:
      H.pop(i)
    elif H[i-1]>=H[i]>=H[i+1]:
      H.pop(i)
  return H

cnt = 0
flg = True
while flg:
  m = max(H)
  if m == 0:
    break
  i = H.index(m)
  d = min(H[i]-H[i+1], H[i]-H[i-1])
  cnt += d
  H[i+1]=max(0,H[i+1]-d)
  H[i-1]=max(0,H[i-1]-d)
  H.pop(i)
  H = trm(H)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = list(map(int,input().split()))
H = [0]+H+[0]
for i in range(N,0,-1):
  if H[i-1]<=H[i]<=H[i+1]:
    H.pop(i)
  elif H[i-1]>=H[i]>=H[i+1]:
    H.pop(i)
cnt = 0
flg = True
while flg:
  m = max(H)
  if m == 0:
    break
  i = H.index(m)
  d = min(H[i]-H[i+1], H[i]-H[i-1])
  cnt += d
  H[i+1]=max(0,H[i+1]-d)
  H[i-1]=max(0,H[i-1]-d)
  H.pop(i)
print(cnt)

Submission status: Wrong Answer

Solution code:
print("I can't")

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int, input().split()))
cnt = 0
for i in range(n):
  fillcnt = 1
  for j in range(1, n-1):
    if h[j-1] != 0 and h[j] == 0:
      fillcnt += 1
  if sum(h) == 0:
    break
  minh = min(filter(lambda x:x!=0, h))
  for j in range(n):
    if h[j] == 0:
      continue
    h[j] -= minh
  cnt += fillcnt * minh
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
h = [int(x) for x in input().split()] + [0]
h = np.array(h,np.int64)
ans = 0
for i in range(N):
    if h[i] > 0:
        j = i + 1
        while h[j] > h[i]:
            h[j] -= h[i]
            j += 1
        nexth = h[j]
        ans += h[j]
        for k in range(i,j+1):
            h[k] -= h[j]
        ans += h[i]
        h[i] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
h = [int(x) for x in input().split()] + [0]
h = np.array(h,np.int64)
ans = 0
for i in range(N):
    if h[i] > 0:
        j = i + 1
        while h[j] > h[i]:
            h[j] -= h[i]
            j += 1
        nexth = h[j]
        h[i] -= h[j]
        ans += h[i]
        h[i] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
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]
#print(listeven)
if len(listodd) == 0:
    print(listeven[0])
elif 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) >= 1:
            del listeven[0]
        ans = sum(listodd)-sum(listeven)
        print(ans)

Submission status: Wrong Answer

Solution code:
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)    
li = len(listans2)
listans3 = []
for n in range(li-1):
    if listans2[n] == listans2[n+1]:
        pass
    else:
        listans3.append(listans[n])
listans3.append(listans2[li-1])         
L = len(listans3)
#print(L)
listodd = [listans3[x] for x in range(L) if x%2 ==1]
#print(listodd)
listeven = [listans3[x] for x in range(L) if x%2 ==0]
#print(listeven)
if len(listodd) == 0:
    print(listeven[0])
elif 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) >= 1:
            del listeven[0]
        ans = sum(listodd)-sum(listeven)
        print(ans)

Submission status: Wrong Answer

Solution code:
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]
#print(listeven)
if len(listodd) == 0:
    print(listeven[0])
elif 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) >= 1:
            del listeven[0]
        ans = sum(listodd)-sum(listeven)
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
m = 0
tmp_max = l[0]
check = False
for i in range(1, n):
    if l[i - 1] > l[i]:
        check = True
    elif check and l[i - 1] < l[i]:
        ans = ans + tmp_max - m
        tmp_max = l[i]
        m = l[i - 1]
        check = False
    else:
        tmp_max = l[i]
ans = ans + tmp_max - m
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
h=np.asarray(list(map(int,input().split())))
cnt=0
while h.max()>0:
  zero=np.asarray([i for i in range(n) if h[i]<=0])
  for i in range(len(zero)-1,-1,-1):
    if i>0 and zero[i]==zero[i-1]+1:
      zero=np.delete(zero,i)
  h=np.where(h>0,h-1,0)
  if len(zero)>0:
    cnt+=np.count_nonzero((0<zero)&(zero<len(h)-1))+1
  else:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
h=np.asarray(list(map(int,input().split())))
cnt=0
while h.max()>0:
  print(h)
  zero=np.asarray([i for i in range(n) if h[i]<=0])
  for i in range(len(zero)-1,-1,-1):
    if i>0 and zero[i]==zero[i-1]+1:
      zero=np.delete(zero,i)
  print('\t{}'.format(zero))
  h=np.where(h>0,h-1,0)
  if len(zero)>0:
    cnt+=np.count_nonzero((0<zero)&(zero<len(h)-1))+1
  else:
    cnt+=1
  print(cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
h = [int(str) for str in input().strip().split()]
h.append(0)

ans = 0
pre_peak = 0
i = 0

while i < N - 1:
    while h[i] <= h[i + 1] and i < N - 1:
        i += 1
    
    peak = h[i]

    while h[i] >= h[i + 1] and i < N - 1:
        i += 1

    ans += peak - pre_peak
    pre_peak = h[i]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
ch=False
#print(cnt,a)
while True:
    my_bool=True
    for i in range(n):
        if my_bool:
            if a[i]!=0:
                my_bool=False
                ch2=True
                a[i]-=1
        else:
            if a[i]!=0:
                a[i]-=1
                ch=True
                ch2=True
            else:
                if ch2:
                    cnt+=1
                ch=False
                ch2=False
    if ch:
        if my_bool:
            pass
        else:
            #print("ch",cnt,a)
            cnt+=1
    #print(cnt,a)
    if my_bool:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = input().split(' ')
harray = []
for z in array:
    z = int(z)
    harray.append(z)
counter = 0
while harray != [0]*N:
    if 0 not in harray:
        a = min(harray)
        for i in range(len(harray)):
            harray[i] -= a
        counter += a
    else:
        zeroarray = [j for j, x in enumerate(harray) if x == 0]
        if len(zeroarray) == 1:
            if zeroarray[0] == 0:
                a = min(harray[1:])
                for y in range(1,N):
                    harray[y] -= a
                counter += a
            elif zeroarray[0] == N-1:
                a = min(harray[:N-2])
                for y in range(N-1):
                    harray[y] -= a
                counter += a
            else:
                a = min(harray[:zeroarray[0]])
                for y in range(zeroarray[0]):
                    harray[y] -= a
                counter += a
                a = min(harray[zeroarray[0]+1:])
                for y in range(zeroarray[0]+1,N):
                    harray[y] -= a
                counter += a
        else:
            for k in range(len(zeroarray)-1):
                if zeroarray[0] != 0:
                    a = min(harray[:zeroarray[0]])
                    for y in range(zeroarray[0]):
                        harray[y] -= a
                    counter += a
                if zeroarray[k+1] - zeroarray[k] == 1:
                    continue
                else:
                    a = min(harray[zeroarray[k]+1:zeroarray[k+1]])
                    for y in range(zeroarray[k]+1,zeroarray[k+1]):
                        harray[y] -= a
                    counter += a
                if zeroarray[-1] != N-1:
                    a = min(harray[zeroarray[-1]+1:])
                    for y in range(zeroarray[-1]+1,N):
                        harray[y] -= a
                    counter += a
        

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(i) for i in input().split(' ')]
a = []
tmp = 0
back = -1

for i in range(1,N-1):
    if H[i] == back:
        continue
    elif H[i] < H[i-1] and H[i] < H[i+1]:
        if back < H[i]:
            back = H[i]
        a.append([back, max(H[tmp:i])])
        tmp = i+1
        back = H[i]

if min(H[tmp:]) < back:
    back = min(H[tmp:])
a.append([back, max(H[tmp:])])

total = 0
s=set()
for abyss, peak in a:
    total += peak - abyss
    s.add(abyss)
total += sum(list(s))
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(i) for i in input().split(' ')]
a = []
tmp = 0
back = -1

for i in range(1,N-1):
    if H[i] <= H[i-1] and H[i] <= H[i+1]:
        if back == H[i]:
            continue
        if back < H[i]:
            back = H[i]
        a.append([back, max(H[tmp:i])])
        tmp = i+1
        back = H[i]

if min(H[tmp:]) < back:
    back = min(H[tmp:])
a.append([back, max(H[tmp:])])

total = 0
s=set()
for abyss, peak in a:
    total += peak - abyss
    s.add(abyss)
total += sum(list(s))
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(i) for i in input().split(' ')]
a = []
tmp = 0
back = -1

for i in range(1,N-1):
    if H[i] <= H[i-1] and H[i] <= H[i+1]:
        if back == H[i]:
            continue
        if back < H[i]:
            back = H[i]
        a.append([back, max(H[tmp:i])])
        tmp = i+1
        back = H[i]

if min(H[tmp:]) < back:
    back = min(H[tmp:])
a.append([back, max(H[tmp:])])
print(a)
total = 0
s=set()
for abyss, peak in a:
    total += peak - abyss
    s.add(abyss)
total += sum(list(s))
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
H = [int(i) for i in input().split(' ')]
a = []
tmp = 0
back = -1

for i in range(1,N-1):
    if H[i] < H[i-1] and H[i] < H[i+1]:
        if back < H[i]:
            back = H[i]
        a.append([back, max(H[tmp:i])])
        tmp = i+1
        back = H[i]
if min(H[tmp:]) < back:
    back = min(H[tmp:])
a.append([back, max(H[tmp:])])

total = 0
s=set()
for abyss, peak in a:
    total += peak - abyss
    s.add(abyss)
total += sum(list(s))
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
cnt=0
ans=0
c=0
for i in range(1000):
    if h==[0]*n:
        break
    for j in range(n):
        if h[j]!=0:
            h[j]-=1
            cnt+=1
        elif h[j]==0 and cnt!=0:
            ans+=1
            cnt=0
            if h==[0]*n:
                print(ans)
                exit()
            break
        elif h[j]==0 and ans==0:
            continue
        if j==n-1:
            ans+=1
            cnt=0
        #print(j)
    #print(h)
#print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
cnt=0
ans=0
c=0
for i in range(1000):
    if h==[0]*n:
        break
    for j in range(n):
        if h[j]!=0:
            h[j]-=1
            cnt+=1
        elif h[j]==0 and cnt!=0:
            ans+=1
            cnt=0
            break
        elif h[j]==0 and ans==0:
            continue
        if j==n-1:
            ans+=1
            cnt=0
        #print(j)
    #print(h)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
x=0
for i in range(1,n-1):
  if h[i-1]>h[i]<h[i+1]:
    a.append(h[i])
    x=1
for i in range(1,n-1):
  if h[i-1]<h[i]>h[i+1]:
    d.append(h[i])
    x=1
if x==0:
  print(h[0])
else:
  if n>=2 and h[0]>=h[1]:
    d.append(h[0])
  if n>=2 and h[-1]>=h[-2]:
    d.append(h[-1])
  print(sum(d)-sum(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
for i in range(1,n-1):
  if h[i-1]>h[i]<h[i+1]:
    a.append(h[i])
for i in range(1,n-1):
  if h[i-1]<=h[i]>=h[i+1]:
    d.append(h[i])
    
if n>=2 and h[0]>=h[1]:
  d.append(h[0])
if n>=2 and h[-1]>=h[-2]:
  d.append(h[-1])
print(sum(d)-sum(a))

Submission status: Wrong Answer

Solution code:
N=int(input())
h=[0]+list(map(int,input().split()))+[0]
d=[]
x=[]
n=0
ind=[i for i in range(N+2)]
for i in range(1,N+2):
  if h[i-1]==h[i]:
    del ind[i+n]
    n-=1
if ind==[0]:
  print(0)
for i in range(len(ind)):
  if i==len(ind)-1:
    break
  if h[ind[i-1]]<h[ind[i]]>h[ind[i+1]]:
    d.append(h[i])
  if h[i-1]>h[i]<h[i+1]:
    x.append(h[i])
print(sum(d)-sum(x))

Submission status: Wrong Answer

Solution code:
def block():
    block=0
    count=0
    mini=200
    while count<=(n-1):
        if h[count]>=1:
            block+=1
            if h[count]<mini:
                mini=h[count]
            count+=1
            while count<=(n-1):
                if h[count]>=1:
                    if h[count]<mini:
                        mini=h[count]
                    count+=1
                else:
                    count+=1
                    break
    return block,mini
                
n=int(input())
h=list(map(int,input().split()))
ans=0
while sum(h)>0:
    bl,m=block()
    ans+=m*bl
    for i in range(n):
        h[i]-=m
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h_L = list(map(int,input().split()))
print(sum(h_L))

Submission status: Wrong Answer

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

m = max(h)

ans = 0
for num in h:
  ans += m-num
print(ans)

Submission status: Wrong Answer

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

flowers = [0] * N

start = 0
end = 0
con = 0

while flowers != height:
  for i in range(0,N):
    if height[i] > flowers[i]:
      start = i
      for j in range(start,N):
        if height[j] > flowers[j]:
          flowers[j] += 1
        elif height[j] == flowers[j]:
          con += 1
          break
      else:
        con += 1
        break

print(con)

Submission status: Wrong Answer

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

flowers = [0] * N

start = 0
end = 0
con = 0

while flowers != height:
  for i in range(0,N):
    if height[i] > flowers[i]:
      start = i
      print(flowers)
      for j in range(start,N):
        if height[j] > flowers[j]:
          flowers[j] += 1
        elif height[j] == flowers[j]:
          con += 1
          break

      else:
        con += 1
        break

print(con)

Submission status: Wrong Answer

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

flowers = [0] * N

start = 0
end = 0
con = 0


while flowers != height:
  for i in range(0,N):
    if height[i] > flowers[i]:
      start = i
      for j in range(start,N):
        if height[j] > flowers[j]:
          flowers[j] += 1
          continue
        elif height[j] == flowers[j]:
          con += 1
          break
      else:
        con += 1
        break
        
print(con)

Submission status: Wrong Answer

Solution code:
N = int(input())
h = list(map(int,input().split()))
l = max(h)
count = 0
for i in range(len(h)):
  if l-h[i]>0:
    count += (l-h[i])
print(count)

Submission status: Wrong Answer

Solution code:
"ABC 116 C - Grand Garden"

if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))

    ans = 0
    while True:
        tmp = list()
        left = -1
        right = -1
        for i in range(N):
            if left is -1 and h[i] is not 0:
                left = i
            elif right is -1 and left is not -1 and h[i] is 0:
                right = i - 1
        if left is -1 and right is -1:
            break
        elif right is -1:
            right = N - 1
        if left is right:
            mizu = h[left]
        else:
            mizu = min(h[left:right])
        ans += mizu
        for i in range(left, right+1):
            h[i] -= mizu

    print(ans)

Submission status: Wrong Answer

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

while True:
    star, end = -1, -1
    frag = False
    min_num = -1

    if min(h) == max(h):
        break

    for i in range(N):
        if h[i] > 0 and not frag:
            star = i
            frag = True
        if h[i] == 0 and frag:
            end = i
            break
    if end == -1:
        end = len(h)

    min_num = min(h[star:end])
    count += min_num
    for j in range(min_num):
        for i in range(star, end):
            h[i] -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
p=h[0]
for i in range(N-1):
  if h[i]<h[i+1]:
    p=h[i+1]
  else:
    p=p

q=1
r=0
if N==1:
    print(p)
elif p==0 and N!=1:
    print(0)
elif p!=0 and N!=1:
    while q<=p:
        if h[0]>=q:
            r=r+1
        else:
            r=r
        for i in range(N-1):
              if h[i]<q and h[i+1]>=q:
                r=r+1
              else:
                r=r
        q=q+1
    print(r)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
p=h[0]
for i in range(N-1):
  if h[i]<h[i+1]:
    p=h[i+1]
  else:
    p=p

q=1
r=0
if p==0:
    print(0)
else:
    while q<=p:
        if h[0]>=q:
            r=r+1
        else:
            r=r
        for i in range(N-1):
              if h[i]<q and h[i+1]>=q:
                r=r+1
              else:
                r=r
        q=q+1
    print(r)

Submission status: Wrong Answer

Solution code:
N=int(input())
h=list(map(int,input().split()))
p=h[0]
for i in range(N-1):
  if h[i]<h[i+1]:
    p=h[i+1]
  else:
    p=p

q=1
r=0
while q<=p:
    if h[0]>=q:
        r=r+1
    else:
        r=r
    for i in range(N-1):
        if h[i]<q and h[i+1]>=q:
            r=r+1
        else:
            r=r
    q=q+1

print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
cout = 0 #最終的な水やり回数
now_water = 0 #現在水やりをしている高さ-1(これは常に最高値を持つ)
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): #花の高さがlist内の最大値になるまで
	i = 0
	while i < n: #now_waterに対して一巡させる
		if list1[i] > now_water:
			func(i)
		else:
			i+=1
	now_water += 1

Submission status: Wrong Answer

Solution code:
n = int(input())

h = list(map(int,input().split()))
c=0
while max(h)>0:   
    ##断裂の数を数える
    while h[0]==0:
      del h[0] 
    while h[-1]==0:
      del h[-1]
    p=0
    for i in range(len(h)-1):
      if h[i]>=1 and h[i+1]<=0:
        p+=1
    ##加算値は断裂+1
    c+=max(1,p+1)
    ##地盤沈下させる
    h = [n-1 for n in h]
    #print("c=",c,"p=",p,"h=",h)
    
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
sum = 0
bottom = 0
for i, hn in enumerate(h):
  if (i == 0) :
    continue
  if (hn < h[i-1]):
    sum += (h[i-1] - bottom)
    bottom = hn
end = bottom if h[n-1] < h[n] else 0
print(sum+end)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
sum = 0
bottom = 0
for i, hn in enumerate(h):
  if (i == 0) :
    continue
  if (hn < h[i-1]):
    print(h[i-1])
    sum += (h[i-1] - bottom)
    bottom = hn
end = bottom if h[n-1] < h[n] else 0
print(sum+end)

Submission status: Wrong Answer

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

water = 0
pre = 0
for now in h_s:
  if now > pre:
    #もしもpreよりもnowの方が大きい場合 pre はnowに内包される
    water += now - pre
    print(pre, now)
  pre = now
print(water)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
count = 0
prev = 0
for i in l:
  if i > prev:
    count += i - prev
    prev = i
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n=int(input())  #数値入力 「N」だけの入力のとき
global h
h=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
global cnt
cnt=0
while sum(h) !=0:
    for L in range(0,len(h)):
        if h[L] != 0:
            for r in range(L+1 ,len(h)):
                if h[r] == 0:
                    #do it
                    for k in range(L,r):
                        h[k]-=1
                    cnt+=1
                    break
            else:
                r = len(h)
                for k in range(L,r):
                    h[k]-=1
                cnt+=1
                break
print(cnt)

Submission status: Wrong Answer

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

n=int(input())  #数値入力 「N」だけの入力のとき
global h
h=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
global cnt
cnt=0
r=len(h)-1
while sum(h) !=0:
    for L in range(0,len(h)):
        if h[L] != 0:
            for j in range(L+1 ,len(h)):
                if h[j] == 0:
                    r = j
                    #do it
                    for k in range(L,r):
                        h[k]-=1
                    cnt+=1
                    break
            else:
                r = len(h)
                for k in range(L,r):
                    h[k]-=1
                cnt+=1
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
inp_h = [int(i) for i in input().split()]

h_max = max(inp_h)
h_len = len(inp_h)
h_sum = sum(inp_h)

print(h_max*h_len-h_sum)

Submission status: Wrong Answer

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