Problem:


Score : 300 points

Problem Statement

N persons are standing in a row. The height of the i-th person from the front is A_i.

We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:

Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.

Find the minimum total height of the stools needed to meet this goal.

Constraints

1 \leq N \leq 2\times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the minimum total height of the stools needed to meet the goal.

Sample Input 1

5
2 1 5 4 3

Sample Output 1

4

If the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.

We cannot meet the goal with a smaller total height of the stools.

Sample Input 2

5
3 3 3 3 3

Sample Output 2

0

Giving a stool of height 0 to everyone will work.



Sample input:
5
2 1 5 4 3


Sample output:
4

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(a-i)
    a=i
  else:
    a=i
print(sum(s))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(i-a)
    a=i
  else:
    a=i
print(sum(s))

Submission status: Wrong Answer

Solution code:
number = int(input())
values = [int(i) for i in input().split()]


max = max(values)
min = min(values)

def answer(values, max, min):
  sum = 0
  if max == min: 
    return 0
  if max < min:
    return min
  average = max / 2
  for index in range(len(values)):
    if max > values[index] > average:
      sum += int(max) - values[index]

  return sum + answer(values,average,min) 

temp = answer(values, max, min)
print(temp)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(i-a)
    a=i
print(sum(s))

Submission status: Wrong Answer

Solution code:
number = int(input())
values = [int(i) for i in input().split()]
sum = 0

max = max(values)
min = min(values)

while max != min:
  temp = max/2
  for element in values:
    if max >= element > temp:
      sum += (int(max) - element)
      print(max, element)
    
  if int(temp) <= min:
    sum += (int(max) - min)
      
  max = int(temp)

print(sum)

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

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

sum = 0
k = a[0]

for i in range(n - 1):
    if a[i] >= a[i + 1]:
        sum += k - a[i + 1]
    else:
        k = a[i + 1]
        sum += 0

print(sum)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    
    for i in range(1, len(a)):
        humidai = max(0, a[i] - a[i-1])
        ans +=  humidai
        a[i] += humidai
    print(ans)
        
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    top = a[0]
    ans = 0

    for height in a:
        if top < height:
            ans += height - top
            top = height

    print(ans)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
max = a[0]
sum = 0
count = 0
result = 0

for i in range(0,n):
  if max > a[i]:
    count+=1
    sum+=a[i]
    if i == n-1:
      result += max*count-sum
  else:
    result += max*count-sum
    
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
max = a[0]
sum = 0
count = 0
result = 0

for i in range(0,n):
  if max > a[i]:
    count+=1
    sum+=a[i]
  else:
    result += max*count-sum
    
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = list(map(int,input().split()))
step=[0]*n
for i in range(n-1):
  step[i+1]+=a[i]+step[i]-a[i+1]
  if step[i+1]<0:
    step[i+1]=0
    
total=sum(step)
print(step)
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

curr = 0
ans = 0
for a in A:
  if curr < a:
    curr = a
    ans += a-curr
print(ans)

Submission status: Wrong Answer

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

stands = 0
for i in range(1,n): 
  stand = member[i] - member[i-1]
  if stand > 0:
    stands += stand
    member[i] += stand
  
print(stands)

Submission status: Wrong Answer

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

total = 0
for i in range(0, N-1):
  step = A[i+1] - A[i]
  if step > 0 :
    total = total + step
    A[i] = A[i] + step
 
print(total)

Submission status: Wrong Answer

Solution code:
# cording:utf-8

# Nの入力
N = int(input())

# 要素数Nのリストを作成
N_i = [0] * N

# N個の整数の入力
N_i = list(map(int, input().split()))
print(N_i)

# 踏み台高さ合計Sumを定義
Sum = 0

# N回の繰り返し
for i in range(1, N):
    # Sum_iを初期化
    Sum_i = 0

    # 直前の人の高さが自分より高ければ
    if (N_i[i-1] + Sum_i) > N_i[i]:
        # 仮のSum_iに踏み台の高さを代入
        Sum_i = N_i[i-1] - N_i[i]
        # N_iに上書き
        N_i[i] = N_i[i] + Sum_i
        # 合計値を算出
        Sum = Sum + Sum_i

print(Sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(0, n - 1):
    h = a[i] - a[i+1]
    if h > 0:
        s += h
        a[i] += h

print(str(s))

Submission status: Wrong Answer

Solution code:
N = input()
A = list(map(int,input().split()))
raw =sum(A)
con = 0

if len(A) == 1:
    print(A[0])
    
else:
    for i in A:
        if A[con] > A[con+1]:
            A[con+1] =  A[con]
        
        if A[con+1] == A[-1]:
            break

        con += 1

    ans = sum(A) - raw
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
print(main)
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print(sum)

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
print(main)
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print("sum = ",sum, "main = ",main)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input(''))
A = input('')
A_N = A.split()
num = 0 
for i in range(1,N):
    if int(A_N[i]) >= int(A_N[i-1]):
        num += 0
    elif (A_N[i]) < (A_N[i-1]):
        num += int(A_N[i-1]) - int(A_N[i])
print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, A = int(input()), list(map(int, input().split()))

    ans = 0
    for idx in range(1, N):
        if A[idx] > A[idx - 1]:
            ans += A[idx] - A[idx - 1]

    print('{}'.format(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

b=0
c=[]

for i in range(n-1):

    c.append(a[i])
    if a[i]>a[i+1]:
        b+=max(c)-a[i+1]

print(b)

Submission status: Wrong Answer

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

a=0
result=0

for i in range(n):
  if A[i-1] > A[i]:
    a = A[i-1] - A[i]
    result += a
    
print(result)

Submission status: Wrong Answer

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

a=0
result=0

for i in range(n-1):
  if A[i] > A[i+1]:
    a = A[i] - A[i+1]
    result += a
    
print(result)

Submission status: Wrong Answer

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

maxi = max(A)
index_maxi = A.index(maxi)

sum = 0
if index_maxi != 0:
    mini_max = max(list(A[:index_maxi]))

    for i in A[index_maxi:]:
        sum += (maxi - i)

    for j in A[:index_maxi]:
        sum += (mini_max - j)

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
MAX = max(a)
ans = 0
flg = False
for i in range(n):
    if a[i] == MAX:
        flg = True
        if i == 0:
            index = i + 1
        else:
            index = i
    if flg:
        ans += MAX - a[i]
for i in range(n):
    if a[i] == MAX:
        break
    else:
        if a[i] <= a[i+1]:
            pass
        else:
            ans += a[i] - a[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
MAX = max(a)
ans = 0
maxflg = False
minflg = False
for i in range(n):
    if a[i] == MAX:
        maxflg = True
        if i == 0:
            index = i + 1
        else:
            index = i
        leftMAX = max(a[:index])
    if maxflg:
        ans += MAX - a[i]

for i in range(n):
    if a[i] == MAX:
        break
    else:
        ans += leftMAX - a[i] 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_height = 0
max_height = A[0]
for i in range(1,len(A)):
    if A[i] < A[i-1]:
        sum_height += max_height - A[i]
    else:
        max_height = A[i]
print(sum_height)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = input()
    string = input()
    max_height = 0
    s = 0
    for c in string:
        if c == " ":
            continue
        h = int(c)
        if h < max_height:
            s += max_height - h
        elif h > max_height:
            max_height = h

    print(s)
resolve()

Submission status: Wrong Answer

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

c = 0
for i in range(1, N):
  b = A[i-1]
  c += A[i] - b if A[i] > b else 0
  
print(c)

Submission status: Wrong Answer

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

c = 0
for i in range(1, N):
  b = A[i-1]
  c += A[i] - b
  
print(c)

Submission status: Wrong Answer

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

ma = vals[0]
res = [0 for _ in range(n)]
for i, val in enumerate(vals):
    if val < ma: 
        res[i] = ma - val
    if ma < val:
        ma = val

print(max(res))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(1,N):
  if A[n] < A[n-1]:
    sum_step += A[n-1] - A[n]
    A[n] = A[n-1]
  print(sum_step)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(0, N):
  if A[n] >= A[n-1]:
    pass
  else:
    sum_step += A[n-1] - A[n]
    A[n] = A[n-1]
  
print(sum_step)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(1, N):
  if A[n] >= A[n-1]:
    pass
  else:
    sum_step += A[n-1] - A[n]
  
print(sum_step)

Submission status: Wrong Answer

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

sum_step = 0

for n in range(1, N):
  max_ = max(A[0:n])
  sum_step += max_ - A[n]
  
print(sum_step)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
mx=0
mae=a[0]
for i in a:
    mx+=i-mae
    mae=i
print(mx)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
mx=0
mae=a[0]
for i in a:
    if i-mae>mx:
        mx=i-mae
    mae=i
print(mx)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


for i in range(n):
    if a[i-1] >= a[i]:
        x = a[i-1] - a[i]
        total += x
        i = i+1
    else:
        total += 0
        i = i+1
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0] * N # 踏み台の高さ
ans = 0
for i in range(1,N):
    h = 0
    if A[i] < A[i-1]:
        h = B[i-1]+A[i-1] - A[i]
    else:
        h = 0
    B[i] = h

for i in range(N):
    ans += B[i]

# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
smallest = A[0]
ans = 0
for x in range(len(A)-1):
	if A[x] < A[x+1]:
		ans += A[x+1] - A[x] 

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
inputs = input().split()
A = list(map(int, inputs[1:]))

sum = 0

for i in range(1, len(A)):
  if A[i] < A[i-1]:
    sum += A[i-1] - A[i]
    A[i] = A[i-1]
    
print(sum)

Submission status: Wrong Answer

Solution code:
##C - Step
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    print(i,A)
    if not A:
        Idx = A.index(max(A))
        ans += max(A)*(len(A) - Idx) - sum(A[Idx::])
        del A[Idx::]
    else:
        break
print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
maxi = a[i]

while True:
    if i == n - 1:
        break
    if a[i + 1] < a[i]:
        ans += (maxi - a[i + 1])
    else:
        maxi = a[i + 1]

    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:

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

x = 0
for a in range(n-1):
    if l[a]>l[a+1] :
        x=l[a] - l[a+1] + x
        l[a+1]=l[a]
    print("l[a],x,l[a+1]=", l[a], x, l[a+1])
print(x)

Submission status: Wrong Answer

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


F=0
for i in range(1,N):
    if A[i]<A[i-1]:
        F+=A[i-1]-A[i]
print(F)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

s=0
for i in range(n-1):
    if a[i]>a[+1]:
        s+=a[i]-a[i+1]
    else:
        continue

print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

s=0
for i in range(len(a)-1):
    if a[i]>=a[+1]:
        continue
    else:
        s+=a[i+1]-a[i]

print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

s=0
for i in range(len(a)-1):
    if a[i]>a[+1]:
        s+=0
    else:
        s+=a[i+1]-a[i]

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
res = [0]*n
for i in range(1, n):
    if arr[i] < arr[i-1]:
        res[i] += (res[i-1] + abs(arr[i-1]-arr[i]))
print(sum(res))

Submission status: Wrong Answer

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

high = 0
cnt = 0
for i in range(1,N):
    if high <= A[i]:
        high = A[i]
    if A[i] >= A[i-1]:
        cnt += high - A[i-1]
        
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(x)

A = x[1:]
step = 0
num_min = 1000

for i in range(len(A)-1):
    if A[i] > A[i+1]:
        for j in range(A[i] - A[i+1]):
            step += 1
            A[i+1] += 1
    else: continue
    
print(step)

Submission status: Wrong Answer

Solution code:
from typing import List

def step(n: int, a: List[int])-> int:
  result = 0
  dai = 0
  for i in range(1,n):
    sub = a[i-1] + dai - a[i]
    print(sub)
    if sub > 0:
      dai = sub      
      result += sub
      continue
    dai = 0
  return result

if __name__ == "__main__":
  n = int(input())
  a = list(map(int, input().split()))
  print(step(n, a))

Submission status: Wrong Answer

Solution code:
x = [list(map(int, input().split())) for i in range(2)]
print(x)

A = x[1]
step = 0
num_min = 1000

for i in range(len(A)-1):
    if A[i] > A[i+1]:
        for j in range(A[i] - A[i+1]):
            step += 1
            A[i+1] += 1
    else: continue
    
print(step)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
hights = int()
for i in range(n-1):
    if(i == n):
        break
    if(a[i] > a[i+1]):
        hights =hights + a[i] - a[i+1]
#        a[i+1] =a[i+1] + (a[i] - a[i+1])
    else:
        continue
#print(a)
print(hights)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = 2 * 10**5 # = int(input())

data = list(map(int, input().split(' ')))

before_max = 0

dai = 0

for i in range(len(data)):
    if(i == 0):
        before_max = data[i]
    else:
        # 自分の身長がこれまでの最大身長よりも高いとき
        if(before_max < data[i]):
            before_max = data[i]
            continue
        # これまでの最大身長よりも自分の身長が低いとき
        elif(before_max > data[i]):
            dai += before_max - data[i]

print(dai)

Submission status: Wrong Answer

Solution code:
num = int(input())
line = list(map(int,input().split()))

mini = line[0]
x = 0
for i in range(1,num):
  if mini > line[1]:
    x += 1
  else:
    mini = line[i]
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = list(map(int,input().split()))
b = a[0]
total=0
for i in a:
  if i<b:
    total+=b-i
  b=i
print(total)

Submission status: Wrong Answer

Solution code:
MOD = 1000000007
from collections import defaultdict as dd,Counter,deque

def si(): return input()
def ii(): return int(input())
def li(): return list(map(int,input().split()))
def mi(): return map(int,input().split())
def out(v): print(v)
def spout(): print(v,end=" ")
def d2b(n): return bin(n).replace("0b","")
def twod(n,m,num):return [[num for x in range(m)] for y in range(n)]
def vow(): return ['a','e','i','o','u']
def let(): return [chr(i) for i in range(97,123)]
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
def ispow2(x):
    return (x and (not(x & (x - 1))))
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i: i+=1
        else:
            n //= i
            factors.append(i)
    if n > 1: factors.append(n)
    return (list(factors))
    
    
n=ii()
a=li()
print(max(a)-min(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
max_num = 0
for num in A:
  if num > max_num:
    max_num = num

border = A.index(max_num)
height = []
before_h = A[0]
for h in A[:border]:
  if before_h <= h:
    height.append(0)
    
  elif before_h > h:
    height.append(before_h-h)
  before_h = h

for h in A[border:]:
  height.append(max_num-h)

print(sum(height))

Submission status: Wrong Answer

Solution code:
loop = int(input())

tall = list(map(int, input().split()))
front = tall[0]
standard = front
result = 0


for i in range(1, loop):
  back = tall[i]
  
  if back-front > 0:
    standard = back
  elif back-front < 0:
    result += standard - back
  front = back

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int,input().split()))
d,f = 0,0
ans = [0]
for i in range(1,N):
  n = array[i]
  d = f - n
  if d >= 0:
    ans.append(d)
  else:
    ans.append(0)
  f = max(ans[0:i])
print( sum(ans) )

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int,input().split()))
d,f = 0,0
ans = []
for i in range(N):
  if i == 0:
    ans.append(0)
    f = array[0]
    continue
  n = array[i]
  d = n - f
  if d >= 0:
    ans.append(d)
  else:
    ans.append(0)
  f = n
print( sum(ans) )

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    highest = A[0]

    for height in range(len(A)-1):
        if A[height] > A[height+1]:
            if A[height] > highest:
                highest = A[height]
            count += highest - A[height+1]

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
sum=0

for i in range(N-1):
    if A[i]>A[i+1]:
        sum+=A[i]-A[i+1]
        A[i+1]=2*A[i]-A[i+1]
    #print(sum)
    #print(A)

print(sum)

Submission status: Wrong Answer

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

sum=0
for i in range(N-1):
    if A[i]>A[i+1]:
        sum+=A[i]-A[i+1]
        A[i+1]=2*A[i]-A[i+1]
    #print(sum)
    #print(A)

print(sum)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
    if a[i+1] < a[i]:
        ans += a[i] - a[i+1]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
heights = list(map(int, input().split()))
steps = [0] * N
for i in range(1, N):
    if heights[i-1] + steps[i-1] > heights[i]:
        steps[i] = 0
    else:
        steps[i] = heights[i] - (heights[i-1] + steps[i-1])
print (sum(steps))

Submission status: Wrong Answer

Solution code:
N = int(input())
heights = list(map(int, input().split()))
steps = [0] * N
for i in range(1, N):
    if heights[i-1] + steps[i-1] > heights[i]:
        steps[i] = 0
    else:
        steps[i] = heights[i] - heights[i-1]
print (sum(steps))

Submission status: Wrong Answer

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

dailist = [0]*N
Alist.append(0)
dailist.append(0)
max = 0
for i in range(N):
  if Alist[i]>max:
    max=Alist[i]
  
  if Alist[i]>Alist[i+1]:
    dailist[i+1]=max-Alist[i+1]
  
del dailist[-1]
print (sum(dailist))

Submission status: Wrong Answer

Solution code:
N = int(input())
line = input()
A = [int(l) for l in line.split()]

total = 0

for i in range(N-1):
  diff = A[i-1] - A[i]
  if diff > 0 :
    total = total + diff
    A[i] = A[i] + diff

print(total)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = input()
N = int(N)
An = list(map(int, input().split()))

cnt = 0
step = []
step_sum = 0

for i in range(0, N):
    if i == 0:
        step.append(0)
        continue
    diff = (An[i - 1] + step[i - 1]) - An[i]
    print('i ', i, 'diff ', diff)
    if diff <= 0:
        step.append(0)
    else:
        step.append(diff)

for num in step:
    step_sum += num

print(step_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
min_a = min(a)
ans = max_a - min_a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
i=n
while i>1:
    maxi=max(a[0:i])
    s+=(i-a.index(maxi))*maxi
    i=a.index(maxi)
print(s-sum(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()[:N]]
temp = 0
overall = 0
# for i in range(N):
#     S = int(input())
#     A.append(S)
for i in range(0, len(A) -1 ):
    if A[i] > A[i+1]:
        temp = A[i] - A[i+1]
        A[i + 1] += 1
        overall += temp
print(overall)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split())) 
s = [0]*(N-1)
 
for n in range(N-1):
  s[n] = A[n] - A[n+1]
  if s[n] <= 0: 
    continue
  else:
    A[n+1] += s[n]

print(int(sum(s)))

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split()
b = int(a[0])
c = 0

for i in range(int(n)):
  if int(a[i]) < b:
    c = b - int(a[1])
  else:
    b = int(a[i])
    
print(c)