abc176c.py
N = int(input())
lis = list(map(int,input().split()))
score = 0
ref = lis[0]
for i in range(1,N):
if ref > lis[i]:
score += ref-lis[i]
else:
ref = lis[i]
print(score)#110ms
for i in range(N) で リスト内の値を呼び出すより、
for a in lis というように直接代入する方が速い。
また、if , elif を使うよりは if,else で完結した方がより速い。
abc176c_r1.py
def solv0():
_ =int(input())
A = list(map(int,input().split()))
cnt = 0
max_hight = 0
for hight in A:
if max_hight < hight:
max_hight = hight
elif max_hight > hight:
cnt += max_hight-hight
return cnt
def solv1():
_ =int(input())
A = list(map(int,input().split()))
cnt = 0
max_hight = 0
for hight in A:
if max_hight <= hight:
max_hight = hight
else:
cnt += max_hight-hight
return cnt
# print(solv0()) #86ms
print(solv1()) #80ms