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())
l=list(map(int,input().split()))
u=max(l)
d=0
i=0
while l[i]!=u:
  if l[i]>l[i+1]:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
for b in range(r,n):
    d=d+(u-l[b])
print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
l=list(map(int,input().split()))
u=max(l)
d=0
i=0
while l[i]!=u:
  if l[i]>l[i+1]:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
for b in range(r,len(l)):
    d=d+(u-l[b])
print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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


highest = 0
diff = 0

a = a[::-1]

for i in a:
    diff = max(highest - i, diff)
    if i > highest:
        highest = i

print(diff)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
inputs = list(map(int,input().split()))
As = []
sum = 0
step =0
for i in inputs:
    As.append(int(i))
try:
    for i in range(len(As)):
        if As[i] < As[i + 1]:
            step = As[i + 1] - As[i]
            sum += step 
except:
    pass

print(sum)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

x = A[0]
cnt = 0
for i in range(1, len(A)):
	# if(A[i] > dp[i-1]+A[i-1] 
	if(A[i] <= A[i-1]):
		cnt += x - A[i]
	else:
		x = A[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  As = list(map(int, input().split()))
  r = 0
  max_a = max(As)
  for a in range(n-1, -1, -1):
    if(a == 0):
      break
    splitAs = As[0:a-1]
    if As[a] < As[a-1]:
      if(max_a not in splitAs):
        max_a = As[a-1]
      tmp = As[a-1] - As[a]
      r += tmp
      if tmp + As[a] < max_a:
        r += max_a - (tmp + As[a])
  print(r)


main()

Submission status: Wrong Answer

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

# N 人が 1 列に並んでおり、前から i 番目の人の身長は Ai です。
# それぞれの人の足元に、高さが 0 以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
# 条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
# この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。

n = I()
a_l = LI()
ans = 0

print(a_l)

for i in range(n-1):
    diff = a_l[i + 1] - a_l[i]
    if diff < 0:
        a_l[i + 1] = a_l[i + 1] + abs(diff)
        ans = ans + abs(diff)
    # print(a_l)
    # print(ans)
print(ans)

Submission status: Wrong Answer

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

tmp=0
count=0
for i in range(N):
  if(i==0):
    tmp=A[0]
  if(tmp<=A[i]):
    #print(A[i])
    tmp=A[i]
  else:
    count+=1

print(count)

Submission status: Wrong Answer

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

tmp=0
count=0
for i in range(N):
  if(i==0):
    tmp=A[0]
  if(tmp<=A[i]):
    #print(A[i])
    tmp=A[i]
  else:
    count+=1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dp = [0 for i in range(n)]
dp[0] = A[0]
cnt = 0
for i in range(1, len(A)):
	# if(A[i] > dp[i-1]+A[i-1] 
	if(A[i] <= A[i-1]):
		dp[i] = dp[i-1]
		cnt += dp[i] - A[i]
	else:
		dp[i] = A[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  As = list(map(int, input().split()))
  r = 0
  max_a = 0
  for a in range(n-1, -1, -1):
    if(a == 0):
      break
    splitAs = As[0:a-1]
    if As[a] < As[a-1]:
      if(0 < len(splitAs)):
        max_a = max(splitAs)
      tmp = As[a-1] - As[a]
      r += tmp
      if tmp + As[a] < max_a:
        r += max_a - (tmp + As[a])

  print(r)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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


highest = 0
diff = 0

a = a[::-1]

for i in a:
    if i > highest:
        highest = i
    diff = max(highest - i, diff)

print(diff)

Submission status: Wrong Answer

Solution code:
import sys
def main(lines):
	line = lines  

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
min_step = 10**9
step = 0
for i in range(N-1):
    if A[i] <= A[i+1]:
        step = A[i+1] - A[i]
        for j in range(N-1):
            if step + A[j] < A[j+1]:
                break
        else:
            min_step = min(min_step, step)
print(min_step)

Submission status: Wrong Answer

Solution code:
# dp[i][j] := i番目の人が選ばれたときの踏み台の最小値

def main():
    # INF = 10 ** 9
    N = int(input())
    A = list(map(int, input().split()))

    # initialize
    dp = [0] * (N + 10)
    # dp[0] = 0

    for i in range(1, N):
        for j in range(N):
            # A[i-1] + h[i-1] < A[i] + h[i]
            if A[i - 1] + dp[i - 1] <= A[i] + j:
                # 条件が破れた時に一つ前の最小になるjを記録したい
                dp[i] = j
                break
    print(sum(dp[:N]))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
max_ind = np.argmax(A)
min_array = np.full(max_ind, A[0])
max_array = np.full(len(A)-max_ind, max(A))
bin_array = np.hstack((min_array, max_array))
hikizan = bin_array - A

y = np.where(hikizan < 0)
if y != 0:
    hikizan[y] = 0
print(np.sum(hikizan))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(n):
  tall = 0
  for j in range(i):
    if (lst[j] > tall):
      tall = lst[j]
  print (i, tall)
  if (lst[i] < tall):
    sa = tall - lst[i]
    print(i,sa)
    ans = ans + sa
    lst[i] = tall
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
maxi = a[0]
ans = 0

for i in range(1, n):
    if a[i - 1] > a[i]:
        ans += maxi - a[i]
    else:
        maxi = 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):
    if a[i-1] - a[i] < 0:
        ans += abs(a[i-1] - a[i])
print(ans)

Submission status: Wrong Answer

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

# N 人が 1 列に並んでおり、前から i 番目の人の身長は Ai です。
# それぞれの人の足元に、高さが 0 以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
# 条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
# この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。

n = I()
a_l = LI()
ans = 0
leng = len(a_l) - 1

print(a_l)

for i in range(leng):
    diff = a_l[i + 1] - a_l[i]
    if diff < 0:
        a_l[i + 1] = a_l[i + 1] + abs(diff)
        ans = ans + abs(diff)
    # print(a_l)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    b.append(c)
    a[j+1]=a[j+1]+c

  if max(b)>-1:
    print(max(b))
  else:
    print(0)
    
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
inputs = input().split()
As = []
sum = 0
step =0
for i in inputs:
    As.append(int(i))
try:
    for i in range(len(As)):
        if As[i] < As[i + 1]:
            step = As[i + 1] - As[i]
            sum += step 
except:
    pass

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    pre = A[0]
    res = 0
    for a in A:
        res += max(0, a - pre)
        pre = a
    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def c_step(n, ls):
    acc = 0
    for i in range(n - 1):
        if ls[i] > ls[i + 1]:
            stool = ls[i] - ls[i + 1]
            ls[i + 1] += stool
            acc += stool
    return acc

Submission status: Wrong Answer

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

max_n = max(a)
min_n = min(a)

result = max_n - min_n 

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = input()
#開業されたN個要素を受け付ける
input_list = list(map(int, input().split()))

i=1

ans = 0

while i < len(input_list):
    if(input_list[i] < input_list[i-1]):
        tmp = input_list[i-1] - input_list[i]
        ans = ans + tmp
        input_list[i] = input_list[i] + 1
    i = i+1

print(ans)

Submission status: Wrong Answer

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

tmp = [0]*N
s = 0

for i in range(1,N):
    if A[i] >= A[i-1]+s:
        s = A[i] - A[i-1] - s
        tmp[i] = s
ans = sum(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ppl=(input().split())
answer=0
for x in range(0,n-1):
    ppl[x]=int(ppl[x])
    ppl[x+1]=int(ppl[x+1])
    if ppl[x]>ppl[x+1]:
        answer+=ppl[x]-ppl[x+1]
        ppl[x+1]=ppl[x]
answer

Submission status: Wrong Answer

Solution code:
N = int(input().rstrip())
As = list(map(int, input().rstrip().split(' ')))

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
step = [0] * N
for i, a in enumerate(A[1:], 1):
    step[i] = -min(0, A[i - 1] + step[i - 1] - a)
print(sum(step))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
maxV = max(list)
for i,ele in enumerate(list):
    if i == len(list)-1:
        continue

    if ele == maxV:
        for j in range(i+1,len(list)):
            hoge = maxV-list[j]
            # print("no", i, "maxV hoge=", hoge)
            ans += hoge
        break

    if ele > list[i+1]:
        hoge = ele - list[i+1]
        # print("no", i, "minus hoge=", hoge)
        ans += hoge

print(ans)

Submission status: Wrong Answer

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

is_break = False
for i in range(len(a_list) - 1):
    if a_list[i] <= a_list[i + 1]:
        continue
    else:
        cur_i = i
        is_break = True
        break

if is_break:
    result = 0
    start_i = cur_i
    end_i = len(a_list)

    # print("start_i", start_i)
    # print("end_i", end_i)

    while True:
        a_max = max(a_list[start_i:end_i])
        # print("a_max", a_max)

        max_index = a_list[start_i:end_i].index(max(a_list[start_i:end_i]))
        # print("max_index", max_index)

        max_sum = a_max * len(a_list[max_index:end_i])
        # print("max_sum", max_sum)

        a_sum = sum(a_list[max_index:end_i])
        # print("a_sum", a_sum)

        result += max_sum - a_sum

        end_i = max_index
        # print("len", len(a_list[start_i:end_i]))
        if len(a_list[start_i:end_i]) == 0:
            print(result)
            break
        # break

else:
    print(0)

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
a = input().split()
list = copy.copy(a)
ans = 0

for i in range(1,n):
    if a[i] < a[i-1]:
        a[i] = a[i-1]
        
for j in range(n):
    if a[j] != list[j]:
        ans += int(a[j]) - int(list[j])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from numba import jit
N1 = int(input(''))
A1 = np.array(list(map(int, input('').split(' '))))

@jit(nopython=True, cache=True)
def func(N,A):
    step = 0
    for k in range(1,N):
        if (np.max(A[:k]) > A[k]):
            step += (N-k) * (np.max(A[:k]) - A[k])
            A[k:] = np.max(A[:k])
    return step
        
print(func(N1,A1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

mx = max(m)
ind = m.index(mx)

c = 0
j = len(m)
for i in reversed(m[ind:]):
    if i < mx:
        d = mx - i
        c += d
ind_i = 0
for i in m[1:ind]:
    if m[ind_i] > i:
        num = m[ind_i] - i
        c+= num
    ind_i += 1
    
print(c)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
            print(mi - a[i+1], mi)
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

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] > a[i - 1]:
        ans += a[i] - a[i - 1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans=0
for i in range(n-1):
  d = a[i-1] - a[i]
  if d<0:
    ans+= d+1
    a[i]=a[i]+d+1
  else:
    continue
    
print(abs(ans))

Submission status: Wrong Answer

Solution code:
def run(x, a_list):
    '''

    '''
    if x == 1:
        print(0)
    else:
        out = 0
        for i,v in enumerate(a_list):
            if i == 0:
                continue
            if i == x-1:
                break
            out += 0 if v < a_list[i-1] else v - a_list[i-1]
            
        print(out)
            


    



if __name__ == '__main__':
    x = int(input())
    a_list = list(map(int, input().split()))
    run(x, a_list)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(max(A)-min(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
print(a)
ans=0
for i in range(n-1):
  d = a[i-1] - a[i]
  if d<0:
    ans+= d+1
    a[i]=a[i]+d+1
  else:
    continue
    
print(abs(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count=0
for i in range(N):
  try:
    a = A[i]
    b = A[i+1]
    if a <= b:
      pass
    else:
      c = abs(a-b)
      count+=c
  except:
    pass
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0

max=max(A)

for i in range(len(A)):
  if A[i] == max:
    a=i
    break

if a==0:
  total=0
  for i in range(len(A)):
    total=total+max-A[i]
  print(total)
  exit()
  
   
tmp=0
for i in range(a):
  if tmp < A[i]:
    tmp=A[i]

#print("tmp",tmp,"a",a,"A[a]",A[a])
  
total=0
for i in range(a):
  total += tmp - A[i]
  #print("total",total)
  
for i in range(a,len(A)):
  total += max - A[i]
  #print("total",total)

print(total)

Submission status: Wrong Answer

Solution code:
def main():
  x = 0
  n = int(input())
  a = list(map(int,(input().split())))
  for i in range(n):
#    print(i)
    if a[i:i+1] < a[i+1:i+2]:
#      print(a[i:i+1],a[i+1:i+2])
      a1 = a[i:i+1][0]
      a2 = a[i+1:i+2][0]
      x +=(a2-a1)
  print(x)
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    cost += max(0, mi - a[-1])
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

ans = 0
maxV = max(list)
for i,ele in enumerate(list):
    if i == len(list)-1:
        continue

    if ele == maxV:
        for j in range(i+1,len(list)-1):
            # print(i, "maxV")
            hoge = maxV-list[j]
            # print(hoge)
            ans += hoge
            break

    if ele > list[i+1]:
        # print(i, "minus")
        hoge = ele - list[i+1]
        ans += hoge

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
            print(mi - a[i+1], mi)
    cost += max(0, mi - a[-1])
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

n = int(input())
A = [int(a) for a in input().strip().split()]

pre = A[0]
s = 0
for a in A:
    ad = max(0, a-pre)
    pre = a + ad
    s += ad
print(s)

Submission status: Wrong Answer

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

for i in range(1,n):
  if a[i-1]+d > a[i]:
    d = abs(a[i-1]-a[i])+d
    ans += d
    
  else:
    d = 0

print(ans)

Submission status: Wrong Answer

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

# N 人が 1 列に並んでおり、前から i 番目の人の身長は Ai です。
# それぞれの人の足元に、高さが 0 以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
# 条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
# この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。

n = I()
a_l = LI()
ans = 0
leng = len(a_l) - 1

for i in range(leng):
    diff = a_l[i + 1] - a_l[i]
    if diff < 0:
        a_l[i + 1] = abs(diff) + 1 
        ans = ans + abs(diff) + 1

print(ans)

Submission status: Wrong Answer

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

Step=[0]
maxt=A[0]
i=0
while i<N-1:
  if A[i]<A[i+1]:
    maxt=max(maxt,A[i+1])
    s=0
  else: # A[i]>=A[i+1]
    s=maxt-A[i+1]
  Step+=[s]
  i+=1
print(sum(Step))

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

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

print(ans)

Submission status: Wrong Answer

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

amax = max(a)
x = a.index(amax)
if x > 0:
   bmax = max(a[:x])
   y = a.index(bmax)
else:
   bmax = 0
   y = 0

ans = 0
for i in range(n):
   if i >= y and i < x:
      ans += max(0, bmax-a[i])
   elif i >= x:
      ans += max(0, amax-a[i])
print(ans)

Submission status: Wrong Answer

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

step = 0
ma = max(A)
idx = A.index(ma)
for i in range(idx-1):
    dif = A[i+1]-A[i]
    if dif < 0:
        step += abs(dif)
for i in range(idx,n):
    dif = ma-A[i]
    step += dif
print(step)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input().split(' ')
print(int(max(b))-int(min(b)))

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
a = A.index(max(A))
l = A[a+1:]
for i in range(1,N):
    bf = A[i-1]
    af = A[i]
    if a <= i:
        ans += max(A)*len(l)-sum(l)
        break
    elif bf > af:
        ans += bf-af

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def abc176_c():
    n = int(input())
    a = list(map(int, input().split(' ')))
    ans = 0

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

    print(ans)



if __name__ == '__main__':
    abc176_c()

Submission status: Wrong Answer

Solution code:
As = list(map(int, input().split()))
 
sum_humidai = 0
 
for person_idx, person_height in enumerate(As):
  
  if person_idx == 0:
    continue
    
  max_front_person = max(As[:person_idx])
  
  if max_front_person > person_height:
    humidai = max_front_person - person_height
    sum_humidai += humidai
 
print(sum_humidai)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
print(sum(b))

Submission status: Wrong Answer

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

s = [0] * n
for i in range(1, n):
    if a[i] - a[i - 1] <= 1:
        s[i] = a[i - 1] - a[i]
        a[i] = a[i - 1]
print(sum(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count=0
for i in range(N):
  try:
    a=A[i]
    b=A[i+1]
    while a>b:
      b+=1
      count+=1
  except:
    pass
print(count)

Submission status: Wrong Answer

Solution code:
#ABC177 C
N = int(input())
A = list(map(int,input().split()))
max = A[0]
F = [0]

for i in range(1,N):
  if max > A[i]:
    F.append(max - A[i])
  else:
    max = A[i]
    F.append(0)

print(F)
print(sum(F))

Submission status: Wrong Answer

Solution code:
N = input()
A = input().split()
S = int(min(A))
L = int(max(A))
print(L-S)

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N = I()
    A = LI()
    a_max = A[0]
    ans = 0
    for i in range(1,len(A)):
        if A[i]>a_max:
            ans += A[i]-A[i-1]
            a_max = A[i]
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
# t=int(input())
# for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
maxa=arr[0]
count=0
for i in range(n):
    if arr[i] > maxa:
        maxa=arr[i]
    else:
        count+=1
print(count)

Submission status: Wrong Answer

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

ans=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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