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())
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 += max(cnt, mh - H[i + 1])
print(cnt)

Submission status: Wrong Answer

Solution code:
addNum = 0
n = input()
s = input().split()

for i in range(len(s)-1):
    if(s[i]>s[i+1]):
        print
        a = int(s[i])
        b = int(s[i+1])
        c =  a-b
        s[i+1] = s[i]
        addNum += c

print(addNum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
s = [0]*N
for i,n in enumerate(A):
    if i == 0:
        continue
    s[i] = max(0, A[i-1] + s[i-1] - A[i])

print(sum(s))
print(s)

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
    print(diff)

print(ans)

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

highest = 0
last = 0
for i in range(n):
    if a[i] >= highest:
        highest = a[i]
        last = i

shortest = highest
for j in range(0, last):
    if a[j] <= shortest:
        shortest = a[j]
        #print(shortest)

print(highest - shortest)

Submission status: Wrong Answer

Solution code:
#
# abc176 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
2 1 5 4 3"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5
3 3 3 3 3"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    M = max(A)
    Mi = A.index(M)
    ans = M - A[N-1]
    for i in range(N-2, -1, -1):
        if i >= Mi:
            ans += M - A[i]
        else:
            if A[i] > A[i+1]:
                ans += A[i] - A[i+1]
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
def divis(l):
    seq = []
    beg, end = 0, 0
    le = len(l)
    for i in range(1,le):
        end = i
        if l[i] < l[i-1]:
            seq.append(l[beg:end])
            beg = i
    seq.append(l[beg:end+1])
    return seq

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    cost = 0
    a = divis(a)
    a.sort()
    le = len(a)
    first = [a[i][-1] for i in range(le)]
    print(first)
    for i in range(le):
        for j in range(len(a[i])):
            cost += max(first[0:i+1]) - a[i][j]
            print(max(first[0:i+1]))
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input(''))
A = np.array(list(map(int, input('').split(' '))))
step = np.zeros(N, dtype=int)
for k in range(1,N):
    if (np.max(A[:k]) > A[k]):
        step[k:] += np.max(A[:k]) - A[k]
        A[k:] = np.max(A[:k])
    else:
        continue
print(np.sum(step))

Submission status: Wrong Answer

Solution code:
A = list(map(int,input().split()))
sm = 0
now = A[0]
for num in A:
    if num < now:
        sm += now-num
    elif num > now:
        now = num
print(sm)

Submission status: Wrong Answer

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

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    A.append(INF)
    ans = 0
    print(A)
    
    for i in range(1,N):
        if A[i] < A[i-1]:
            ans += abs(A[i-1]-A[i])
            A[i] = A[i-1]
        
    print(ans)
            
main()

Submission status: Wrong Answer

Solution code:

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

_sum = 0

for e in range(len(a_list)):
    # print('aaa')
    if e != 0 :
        # print('bbb')
        if a_list[e] < a_list[e - 1] :
            # print('ccc')
            _sum = _sum + (a_list[e - 1] - a_list[e])

print(_sum)

Submission status: Wrong Answer

Solution code:
import sys
li  =   lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw  =   lambda : sys.stdin.readline().strip().split()
ni  =   lambda : int(sys.stdin.readline().strip())
nsi =   lambda : sys.stdin.readline().strip()

from collections import defaultdict as df
import math

n=ni()
l=list(map(int,input().split()))
mn=l[0]
ans=0
for i in range(1,n):
    if(mn<l[i]):
        mn=l[i]
        print(l[i])
    else:
        ans+=mn-l[i]
print(ans)

Submission status: Wrong Answer

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

r = 0

for a in range(len(As)-1, -1, -1):
  if As[a] < As[a-1]:
    r += As[a-1] - As[a]
print(r)

Submission status: Wrong Answer

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

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

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

print(diff_sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
H = list(map(int, input().split()))
mh = 0
ans = 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 = max(ans, mh - H[i + 1])
    ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
An = [int(val) for val in input().split()]

# 各踏み台を初期化
Fn = [0 for _ in range(N)]

an_1 = An[0]
fn_1 = 0

for i in range(1, N):
    an = An[i]
    fn =  max(0, an - an_1 - fn_1)

    Fn[i] = fn
    fn_1 = fn
    an_1 = an

sum = 0
for fi in Fn:
    sum += fi

print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def Step():
    
    num = int(input())

    data = list(map(int,input().split()))
        
    print(max(data) - min(data))
        
if __name__ == '__main__':
    Step()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
stool = 0
for i in range(N):
    for j in range(i+1,i+2):
        if j >= N:
            break
        if A[i] > A[j]:
            stool += A[i] - A[j]
            A[j] += 1

print(stool)

Submission status: Wrong Answer

Solution code:
num = int(input())
height = list(map(int,input().split()))
count = 0

for i in range(len(height) - 1):
    while height[i] < height[i + 1]:
        height[i] += 1
        count += 1
print(count)

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

tmp=0

for i in range(a):
  if tmp < i:
    tmp=i

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


print(total)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
stool = 0
for i in range(N):
    for j in range(i+1,i+2):
        if j >= N:
            break
        if A[i] > A[j]:
            stool += A[i] - A[j]
            A[j] += 1
            continue


print(stool)

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = input().split()
numbers = list(map(int,numbers))
m = 0
gross_count = 0
for n in numbers:
    if m > n:
        gross_count += (m-n)
        print(gross_count)
    else:
        m = n
print(gross_count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
s = [0]*N

for i,n in enumerate(A[1:]):
    s[i] = max(0, A[i] - A[i-1])

print(sum(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == 0:
        ans = 0
    else:
        if A[i] > A[i-1]:
            ans = 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
max_len = A[0]
for i in range(1, len(A)):
    if A[i-1] < A[i]:
        max_len = A[i]
    else:
        ans += max_len - A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
mn = min(a)
print(mx-mn)

Submission status: Wrong Answer

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

    diff = a_before-a_after

    if diff < 0:
        ans += abs(diff)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    B = [0 for i in range(n)]
    for i in range(n - 1):
        B[i+1] = max(0, A[i] - A[i+1])
    if n > 1:
        B[-1] = max(0, A[-2] + B[-2] - A[-1])
    res = sum(B)
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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:
        pass
    else:
        ans += diff
        A[i] += diff
print(ans)

Submission status: Wrong Answer

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

ans = 0

#a.insert(0,0)
a.append(999999999)
tmp = 0
for i in range(n):
  #print(tmp)
  if a[i] <= a[i+1]:
    tmp = 0
    continue
  else:
    tmp = a[i] - a[i+1]
    a[i+1] += tmp
    ans += tmp
    
print(ans)
#print(a)

Submission status: Wrong Answer

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

ans=0
l2=[l[0]]
#print(l2)

for i in range(1,n):
    if l[i-1] <= l[i]:
        l2+=[l[i]]
        continue
    else:
        l2+=[l2[i-1]]
        ans+=(l2[i]-l[i])

print(ans)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0

for i, j in enumerate(a):
    try:
        if j < a[i - 1]:
            b = a[i - 1] - j
            count += b
            j += b
        else:
            pass
    except IndexError:
        pass

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
H = list(map(int, input().split()))
mh = 0
ans = 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]:
            ans = max(ans, mh - H[i + 1])

print(ans)

Submission status: Wrong Answer

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

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

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())
listA=list(map(int,input().split()))
listB=[0]

for i in range(len(listA)-1):
  if listA[i+1]>listA[i]:
    listB.append(listA[i+1]-listA[i])

print(sum(listB))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0

max=max(A)

a=A.index(max)
tmp=0

for i in range(a):
  if tmp < i:
    tmp=i

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


print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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] - a[i+1]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0

for i, j in enumerate(a):
    try:
        if j < a[i - 1]:
            b = a[i - 1] - j
            count += b
        else:
            pass
    except IndexError:
        pass

print(count)

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]:
        diff = A[i] - A[i - 1]
        sum_ += diff
print(sum_)

Submission status: Wrong Answer

Solution code:
ran = int(input())
Ns = list(map(int, input().split()))
ans = 0
base = Ns[0]
for i in range(1, ran):
    if Ns[i] < Ns[i-1]:
        preans = base - Ns[i]
        ans += preans
    else:
        base = Ns[i]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

    if ele > list[i+1]:
        ans = ans +  ele - list[i+1] + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [*map(int, input().split())]
s = 0
pre = A[0]
for now in A[1:]:
    d = now - pre
    if d>0:
        s += d
    pre = now
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
step = max(A)-min(A)
print(step)

Submission status: Wrong Answer

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

sum=0
l.sort()
for i in range(len(l)-1):
    if l[i+1]>l[i]:
        sum+=l[i+1]-l[i]

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
a=get_array()
print(max(a)-min(a))

Submission status: Wrong Answer

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

ans=0
l2=[l[0]]
#print(l2)

for i in range(1,n):
    if l[i-1] <= l[i]:
        l2+=[l[i]]
        continue
    else:
        l2+=[l2[i-1]]
        ans+=(l2[i-1]-l[i])

print(ans)

Submission status: Wrong Answer

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

before = 0
d = [0] * N
for i in range(N):
    if i == 0:
        before = i
        continue

    if A[before] > A[i]:
        d[i] = (A[before] + d[before]) - A[i]
        before = i
    else:
        before = i

print(sum(d))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int , input().split()))
mx = As[-1]
sm = 0
for i in range(len(As)-2,-1,-1):
  if As[i] < mx:
    sm+= mx - As[i]
  mx = As[i]
print(sm)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from collections import defaultdict
import sys

N = int(input())
A = [int(x) for x in input().split()]

step = 0

prev = 0

for a in A:
    if a < prev:
        step = max(step, prev-a + 1)
        a += step

    prev = a
#    print(a)

print(step)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

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

mini = A[0]
ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def divis(l):
    seq = []
    beg, end = 0, 0
    le = len(l)
    for i in range(1,le):
        end = i
        if l[i] < l[i-1]:
            seq.append(l[beg:end])
            beg = i
    seq.append(l[beg:end+1])
    return seq

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    cost = 0
    a = divis(a)
    a.sort()
    for i in a:
        for j in range(len(i)-1):
            cost += i[-1] - i[j]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
buf = 0

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

Submission status: Wrong Answer

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

mini = A[0]
ans = 0

for i in range(len(A) - 1):
    if A[i] < A[i+1]:
        ans += A[i+1] - 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):
    tmp = A[i-1] - A[i]
    if A[i-1] > A[i]:
        A[i] += tmp
        ans += tmp
print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
tmp=l[0]
ans=0
for i in range(n-1):
    if l[i+1]<=l[i]:
        ans+=(tmp-l[i+1])
    else:
        tmp=l[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(1,n):
  d=A[i]-A[i-1]
  if d>0:
    ans += d
    A[i]+=d
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]>a[i-1]:
    ans+=a[i]-a[i-1]
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):
  e = a[i+1]-a[i]
  if e > 0:
    s += e
  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(n-1):
	s += max(a[i+1] - a[i],0)
print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
 
 
def main():
    n=int(input())
    a=list(map(int,input().split(" ")))
    s=0
    for x in range(1,n):
        s=s+max(0,a[x]-a[x-1])
        a[x]=a[x-1]
    print(s)


#-----------------------------BOSS-------------------------------------!
# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = map(int, input().split())
    A = list(map(int, input().split()))[::-1]
    cont = 0
    ans_val = 0
    for i in range(len(A) - 1):
        if A[i] <= A[i+1]:
            cont += 1
            diff = A[i+1] - A[i]
            ans_val += diff * cont
        else:
            cont = 0
    return ans_val

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

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])
else:
   bmax = 0

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

Submission status: Wrong Answer

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

a_tmp = a_list[0]

sum = 0
for i in range(1, len(a_list)):
    if a_list[i] > a_tmp:
        sum += a_list[i] - a_tmp
        a_tmp = a_list[i]
    else:
        a_tmp = a_list[i]

print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
As = list(map(int, input().split()))
res = 0
for i in range(N-1):
    if As[i] < As[i+1]:
        res += As[i+1] - As[i]
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(a_list) - 1):
  if a_list[i] > a_list[i+1]:
    score += a_list[i] - a_list[i+1]
    
print(score)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = a[0]
for i in range(n-1):
    ans += max(a[i+1]-a[i],0)
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]>a[i-1]:
        ans+=a[i]-a[i-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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