problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02578
s067401962
Accepted
# -*- coding: utf-8 -*- n = int(input()) a = list(map(int, input().split())) l = [] for i in range(len(a) - 1): if a[i + 1] < a[i]: l.append(a[i]-a[i + 1]) a[i + 1] = a[i] print(sum(l))
p02578
s039327170
Accepted
N = int(input()) A = list(map(int,input().rstrip().split(" "))) ans = 0 minnow = A[0] for i in range(1,N): if(minnow > A[i]): ans += minnow - A[i] else: minnow = A[i] print(ans)
p02578
s856400424
Accepted
N = int(input()) A = list(map(int, input().split())) mx = A[0] ans = 0 for i in range(1, N): if A[i] < mx: ans += mx-A[i] elif A[i] > mx: mx = A[i] print(ans)
p02578
s009454512
Accepted
n = int(input()) a = list(map(int, input().split())) fumi_sum = 0 for i in range(1,n): if a[i] < a[i-1]: fumi_sum += a[i-1] - a[i] a[i] += a[i-1] - a[i] print(fumi_sum)
p02578
s697495275
Accepted
N = int(input()) L = list(map(int,input().split())) ans=0 for i in range(N-1): if L[i]-L[i+1]>0: ans += L[i]-L[i+1] L[i+1]=L[i] print(ans)
p02578
s700686225
Accepted
N = int(input()) A = [int(i) for i in input().split()] pre_a = A[0] ans = 0 for a in A[1:]: ans += max(0, pre_a - a) pre_a = max(pre_a, a) print(ans)
p02578
s235648335
Accepted
N = int(input()) ARR = list(map(int,input().split())) def calculate(n, arr): currentHeight = arr[0] result = 0 for i in range(1,n): if arr[i] < currentHeight: result += (currentHeight - arr[i]) else: currentHeight = arr[i] return result res = calculate(N, ARR) print(res)
p02578
s757177519
Accepted
n=int(input()) row=list(map(int,input().split())) s=0 for i in range(1,n): if row[i-1]>row[i]: s+=row[i-1]-row[i] row[i]=row[i-1] print(s)
p02578
s511771142
Accepted
N=int(input()) A=list(map(int,input().split())) ans=0 for i in range(N-1): if A[i]>A[i+1]: plus=abs(A[i]-A[i+1]) A[i+1]+=plus ans+=plus print(ans)
p02578
s973924003
Accepted
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] A[i+1] = A[i] print(ans)
p02578
s078269767
Accepted
N=int(input()) s=[int(x) for x in input().split()] ans=0 for i in range(N-1): if s[i]>s[i+1]: ans+=(s[i]-s[i+1]) s[i+1]=s[i+1]+(s[i]-s[i+1]) print(ans)
p02578
s210094489
Accepted
n = int(input()) a = list(map(int, input().split())) tmp = a[0] ans = 0 for i in a: if i < tmp: ans += tmp-i else: tmp = i print(ans)
p02578
s193462719
Accepted
# coding: utf-8 # Your code here! n = int(input()) a = list(map(int,input().split(" "))) dai = 0 for i in range(1,n): if a[i] < a[i-1]: dai += a[i-1] - a[i] a[i] = a[i-1] print(dai)
p02578
s308799332
Accepted
N = int(input()) a = list(map(int, input().split())) count = 0 i = 0 for i in range(N-1): if a[i] <= a[i+1]: continue elif a[i] > a[i+1]: diff = a[i] - a[i+1] count = count + diff a[i+1] = a[i] print(count)
p02578
s957687434
Accepted
N = int(input()) people = [int(i) for i in input().split()] step = 0 front = people[0] for i in range(N): if front > people[i]: step += front - people[i] else: front = people[i] print(step)
p02578
s890563300
Accepted
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-1]-a[i]) a[i]=a[i-1] print(cnt)
p02578
s990969859
Accepted
n = int(input()) a = list(map(int, input().split())) count = 0 i = 1 while i < len(a): if a[i] < a[i-1]: count += a[i-1] - a[i] a[i] = a[i-1] i += 1 print(count)
p02578
s017169898
Accepted
N=int(input()) A=list(map(int, input().split())) h=0 for i in range(1,N): if A[i]<A[i-1]: h+=A[i-1]-A[i] A[i]+=A[i-1]-A[i] print(h)
p02578
s758576921
Accepted
n = int(input()) a = list(map(int,input().split())) bmax = a[0] st = 0 for i in range(1,n): if a[i] < bmax: st += bmax - a[i] else: bmax = a[i] print(st)
p02578
s864089379
Accepted
n = int(input()) a = list(map(int,input().split())) t = a[0] ans = 0 for i in range(1,n): if a[i] < t: ans += t-a[i] else: t = a[i] print(ans)
p02578
s575689524
Accepted
N = int(input()) A = list(map(int, input().split())) dif = 0 sum = 0 for i in range(N - 1): if A[i] > A[i + 1]: dif = A[i] - A[i + 1] sum += dif A[i +1] = A[i + 1] + dif print(sum)
p02578
s058011483
Accepted
number = int(input()) tall = list(map(int, input().split())) addition = 0 for each in range(1, number): difference = tall[each - 1] - tall[each] if difference >= 0: addition += difference tall[each] += difference print(addition)
p02578
s500817892
Accepted
n = int(input()) L = list(map(int,input().split())) maxh = L[0] sum1 = 0 for i in range(1,n): if L[i] > maxh: maxh = L[i] else: sum1 += maxh-L[i] print(sum1)
p02578
s386256938
Accepted
n=int(input()) heights=list(map(int,input().split())) step=0 for i in range(n-1) : if heights[i+1] < heights[i] : step += heights[i] - heights[i+1] heights[i+1] = heights[i] print(step)
p02578
s507265312
Accepted
def inp(): return input() def iinp(): return int(input()) def inps(): return input().split() def miinps(): return map(int,input().split()) def linps(): return list(input().split()) def lmiinps(): return list(map(int,input().split())) def lmiinpsf(n): return [list(map(int,input().split()))for _ in range(n)] n = iinp() a = lmiinps() ans = 0 for i in range(n-1): if a[i+1] < a[i]: ans += (a[i] - a[i+1]) a[i+1] = a[i] print(ans)
p02578
s897549325
Accepted
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-1]-A[i] A[i]=A[i-1] print(ans)
p02578
s640586095
Accepted
#template def inputlist(): return [int(j) for j in input().split()] #template N = int(input()) A = inputlist() maxa = A[0] ans= 0 for i in range(1,N): if A[i] < maxa: ans += maxa - A[i] else: maxa = A[i] print(ans)
p02578
s542804971
Accepted
n = int(input()) a = list(map(int,input().split())) m = a[0] stool = 0 for i in range(1,n): if a[i]>m: m = a[i] stool = stool + m-a[i] print(stool)
p02578
s932232536
Accepted
n = int(input()) h = [int(i) for i in input().split()] m = h[0] s = 0 for i in h: if(i > m): m = i else: s += m - i print(s)
p02578
s510912903
Accepted
N = int(input()) l = input().split() cnt = 0 current = int(l[0]) for i in range(1, N): now = int(l[i]) if now >= current: current = now if now < current: cnt += current - now print(cnt)
p02578
s185151104
Accepted
import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n = int(input()) A = list(map(int, input().split())) for i in range(n): if i == 0: max = A[i] else: if max > A[i]: ans += max - A[i] else: max = A[i] print(ans)
p02578
s008019001
Accepted
N = int(input()) A = input().split() count = 0 for i in range(N): A[i] = int(A[i]) for i in range(N-1): if A[i] > A[i+1]: count += A[i] - A[i+1] A[i+1] = A[i] print(count)
p02578
s584695881
Accepted
n = int(input()) a = [int(i) for i in input().split()] ans = 0 for i in range(1,len(a)): if a[i-1] > a[i]: ii = a[i-1] - a[i] a[i] += ii ans += ii print(ans)
p02578
s979972434
Accepted
N = int (input ()) A = [int (x) for x in input().split()] X = A[0] P = 0 for i in range (N-1): if A[i+1] < X: P += X-A[i+1] elif A[i+1] > X: X = A[i+1] print (P)
p02578
s726206899
Accepted
N = int(input()) A = list(map(int,input().split())) B = A[0] ans = 0 for i in range(N): if B > A[i]: ans += abs(A[i] - B) B = max(A[i],B) print(ans)
p02578
s959978602
Accepted
n=int(input()) a=list(map(int,input().split())) tmp=a[0] ans=0 for i in a: if tmp>i: ans+=tmp-i else: tmp=i print(ans)
p02578
s011563356
Accepted
N = int(input()) A = list(map(int,input().split())) M=A[0] ans = 0 for i in range(1,N): if A[i]<M: ans += M - A[i] else: M = A[i] print(ans)
p02578
s522444465
Accepted
def main(): 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-1]-a[i] a[i] = a[i-1] print(ans) if __name__ == "__main__": main()
p02578
s379713987
Accepted
def main(): number_of_person = int(input()) array = [int(x) for x in input().split()] pre_h = 0 step_total = 0 for height in array: step_total += max(pre_h - height, 0) pre_h = max(height, pre_h) return step_total if __name__ == '__main__': ans = main() print(ans)
p02578
s151149132
Accepted
if __name__ == "__main__": n = int(input()) ai = list(map(int, input().split())) li = [] for i in range(n - 1): if ai[i] > ai[i + 1]: li.append(ai[i] - ai[i + 1]) ai[i+1]=ai[i] else: pass print(sum(li))
p02578
s110297204
Accepted
n=int(input()) arr=list(map(int,input().split())) ma=0 ans=0 for i in range(1,n): if arr[i]<arr[i-1]: ans+=arr[i-1]-arr[i] arr[i] = arr[i - 1] print(ans)
p02578
s859524540
Accepted
import numpy as np from numba import jit N = int(input('')) A1 = np.array(list(map(int, input('').split(' ')))) @jit(nopython=True) def func(A): step = 0 for k in range(0,N-1): if A[k] > A[k+1]: add = A[k] - A[k+1] step += add A[k+1] += add return step print(func(A1))
p02578
s801436126
Accepted
n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(1,n): ans += max(a[i-1]-a[i],0) a[i] = max(a[i-1],a[i]) print(ans)
p02578
s560815092
Accepted
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] print(total)
p02578
s741380786
Accepted
n = int(input()) A = list(map(int,input().split())) x = A[0] ct = 0 for a in A: if x < a: x = a elif x > a: ct += (x-a) print(ct)
p02578
s226508433
Accepted
n=int(input()) a=list(map(int,input().split())) mx=0 s=0 for i in a: if mx<i: mx=i s+=mx-i print(s)
p02578
s282985910
Accepted
n = int(input()) a = list(map(int,input().split())) res = 0 pre = a[0] for i in range(1, n): if pre <= a[i]: pre = a[i] continue res += pre - a[i] print(res)
p02578
s066547951
Accepted
n = int(input()) a = list(map(int, input().split())) k = 0 m = a[0] for i in range(1, n): if m > a[i]: k += m-a[i] else: m = a[i] print(k)
p02578
s966428990
Accepted
def solve(n,arr): maxh = 0 h = 0 for i in range(1,n): curr = arr[i] curh = arr[i-1] f = max(curr,curh) maxh = max(f,maxh) if curr < maxh: h += maxh - curr # print(f"curr:{curr},curh:{curh},maxh:{maxh}") # print(f"h:{h}") return h n = int(input()) arr = list(map(int, input().strip().split())) print(solve(n,arr))
p02578
s299201472
Accepted
n=int(input()) a=list(map(int, input().split())) res=0 max=a[0] for i in range(1,n): if a[i]<max: res+=max-a[i] else: max=a[i] print(res)
p02578
s572963908
Accepted
import sys N = sys.stdin.readline() Alst = list(map(int, sys.stdin.readline().split())) now = 1 x = 0 for i in Alst: if now < i: now = i else: x += (now - i) print(x)
p02578
s915267642
Accepted
N=int(input()) A=list(map(int, input().split())) c=0 for i in range(N-1): if A[i]>A[i+1]: c=c+(A[i]-A[i+1]) A[i+1]=A[i] print(c)
p02578
s643023095
Accepted
N = int(input()) L = list(map(int, input().split())) ma = max(L) mi = L.index(ma) S = 0 nma = L[0] for i in range(1, len(L)): if mi <= i: S += ma - L[i] else: nma = max(nma, L[i]) S += nma - L[i] print(S)
p02578
s065342407
Accepted
n = int(input()) a = list(map(int,input().split())) cnt = 0 for i in range(n-1): if a[i+1]<a[i]: cnt += a[i]-a[i+1] a[i+1] = a[i] print(cnt)
p02578
s135421370
Accepted
n = int(input()) a = [int(i) for i in input().split(' ')] result = 0 max_height = 0 for i in range(n): an = a[i] if i == 0: max_height = an max_height_idx = 0 continue if an >= max_height: max_height = an max_height_idx = i continue result += (max_height - an) print(result)
p02578
s669064125
Accepted
N = int(input()) A = list(map(int, input().split())) ap = 0 xp = 0 xcount = 0 for i in range(N): a = A[i] x = (ap+xp)-a if x <= 0: xp = 0 else: xp = x xcount = xcount + xp ap = a print(xcount)
p02578
s674460512
Accepted
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): N = int(input()) A = list(map(int, input().split())) arr = A[0] ans = 0 for i in A: ans += abs(arr - i) if i <= arr else 0 arr = max(arr, i) print(ans) if __name__ == "__main__": main()
p02578
s412576046
Accepted
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, copy, time from fractions import gcd import numpy as np sys.setrecursionlimit(10**8) INF = float('inf') MOD = 10**9+7 EPS = 10**-7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) n = int(input()) a_list = np.array(list(map(int, input().split()))) a_mx = np.maximum.accumulate(a_list) ans = (a_mx - a_list).sum() print(ans)
p02578
s611118435
Accepted
def main(): n = int(input()) ai = list(map(int, input().split())) cnt = 0 for i in range(n): if i != n-1: if ai[i] > ai[i+1]: cnt += ai[i]-ai[i+1] ai[i+1] = ai[i] print(cnt) if __name__ == "__main__": main()
p02578
s922253483
Accepted
from sys import stdin input = stdin.readline n = int(input()) a = list(map(int,input().split())) ma = -1 res = 0 for i in a: res += max(ma - i,0) ma = max(ma,i) print(res)
p02578
s294483600
Accepted
n = int(input()) li = list(map(int,input().split())) ans = 0 for i in range(n): if i > 0: if li[i-1] > li[i]: ans += li[i-1]-li[i] li[i] += (li[i-1]-li[i]) print(ans)
p02578
s575416470
Accepted
n=int(input()) a=list(map(int,input().split())) count=0 high=0 for i in range(n): if high>=a[i]: count+=high-a[i] else: high=a[i] print(count)
p02578
s870972199
Accepted
N = int(input()) *A, = map(int, input().split()) ans = 0 for i in range(N-1): v1, v2 = A[i], A[i+1] if v1<=v2: continue ans += v1-v2 A[i+1] = v1 print(ans)
p02578
s309760350
Accepted
import math def main(): n = int(input()) a_li = list(map(int,input().split())) ans = 0 for i in range(1,n): if(a_li[i] >= a_li[i-1]): continue ans += a_li[i-1] - a_li[i] a_li[i] = a_li[i-1] print(ans) if __name__ == "__main__": main()
p02578
s932251910
Accepted
n = input() a_list = list(map(int, input().split())) cnt = 0 tmp = 0 for a in range(len(a_list)-1): if (a_list[a] > a_list[a+1]): cnt += a_list[a] -a_list[a+1] a_list[a+1] += a_list[a] -a_list[a+1] # print(cnt) print(cnt)
p02578
s060742609
Accepted
n=int(input()) a=list(map(int,input().split())) dai=[0]*n x=a[0] for i in range(n-1): if a[i+1]-x<0: dai[i+1]=x-a[i+1] x=a[i+1]+dai[i+1] else: x=a[i+1] print(sum(dai))
p02578
s088404675
Accepted
N = int(input()) As = list(map(int, input().split())) ans = 0 tall = int(As[0]) for A in As: if(tall > A): ans += tall - A else: tall = A print(ans)
p02578
s887097476
Accepted
n=int(input()) a=[int(i) for i in input().split()] max_height=0 ans=0 for i in a: if max_height>i: ans+=max_height-i else: max_height=i print(ans)
p02578
s014768956
Accepted
N, *A = map(int, open(0).read().split()) ans = [] p = A[0] for i in range(N): if i == 0: continue if p > A[i]: ans.append(p - A[i]) else: p = A[i] print(sum(ans))
p02578
s363342958
Accepted
n = int(input()) a = list(map(int, input().split())) ret = 0 now = a[0] for i in range(1, n): if now > a[i]: ret += now - a[i] a[i] = now now = a[i] print(ret)
p02578
s633085587
Accepted
n = int(input()) a = list(map(int, input().split())) lmax = a[0] ans = 0 for i in a: ans += max(0, lmax-i) lmax = max(lmax, i) print(ans)
p02578
s604920988
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1, len(A)): height = max(0, A[i-1] - A[i]) A[i] += height ans += height print(ans)
p02578
s563696995
Accepted
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 += (max - a[i]) print(sum)
p02578
s293974296
Accepted
n=int(input()) L=list(map(int,input().split())) max=0 ans=0 for i in range(n): if max>=L[i]: ans+=max-L[i] else: max=L[i] print(ans)
p02578
s754117466
Accepted
n = int(input()) a = list(map(int, input().split())) b = [0] * n b[0] = 0 for i in range(1, n): if a[i-1] + b[i-1] > a[i]: b[i] = a[i-1] + b[i-1] - a[i] else: b[i] = 0 c = 0 for i in range(1, n): c = c + b[i] print(c)
p02578
s520690040
Accepted
n = int(input()) ls = list(map(int,input().split())) sm = 0 for i in range(1,n): if ls[i] < ls[i-1]: sm += ls[i-1]-ls[i] ls[i] = ls[i-1] print(sm)
p02578
s242029254
Accepted
n=int(input()) a=list(map(int, input().split())) l=a[0] sm=0 for h in a: if(h<l): sm+=(l-h) elif(h>l): l=h print(sm)
p02578
s522025593
Accepted
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() a = LI() m = a[0] ans = 0 for i in range(1, n): if a[i] <= m: ans += m - a[i] else: m = a[i] print(ans)
p02578
s909387309
Accepted
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-1]-a[i] a[i] = a[i-1] print(ans)
p02578
s627935865
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N): if i == 0: tmp = A[i] else: if tmp > A[i]: ans += (tmp - A[i]) else: tmp = A[i] print(ans)
p02578
s283385808
Accepted
N, A = input(), [int(v) for v in input().split()] # max(abs(x-y) for x, y in zip(A, A[1:])) stool = A[0] ans = 0 for i, h in enumerate(A): if h < stool: ans += stool - h stool = max(stool, h) print(ans)
p02578
s267645385
Accepted
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N=int(input()) A=list(map(int,input().split())) ans=0 tmp=A[0] for x in A[1:]: if x<tmp: ans+=tmp-x tmp=max(tmp,x) print(ans)
p02578
s711960821
Accepted
s = int(input()) arr = list(map(int, input().split())) ans = 0 for i in range(1,s): if arr[i] < arr[i-1]: ans += (arr[i-1]-arr[i]) arr[i] = arr[i-1] print(ans)
p02578
s720281106
Accepted
n = int(input()) a = list(map(int, input().split())) level = 0 step = 0 for i in range(n): if level < a[i]: level = a[i] else: step += level - a[i] print(step)
p02578
s478687725
Accepted
import math import sys import itertools from math import gcd from math import sqrt from sys import stdin def input() : return stdin.readline().rstrip() def mips(): return map(int,input().split()) def ii(): return int(input()) sys.setrecursionlimit(10**9) N = ii() A = [i for i in mips()] ans = 0 for i in range(N-1): if A[i] > A[i+1]: ans += abs(A[i]-A[i+1]) A[i+1] = A[i] print(ans)
p02578
s242643276
Accepted
n = int(input()) A = list(map(int, input().split())) m = A[0] ans = 0 for a in A[1:]: m = max(m,a) if m > a: ans += m-a print(ans)
p02578
s266152886
Accepted
n = int(input()) al = list(map(int, input().split())) ans = 0 for i in range(n-1): if al[i] >= al[i+1]: ans += al[i]-al[i+1] al[i+1] += (al[i]-al[i+1]) print(ans)
p02578
s144797151
Accepted
n = int(input()) nums = list(map(int, input().split())) ans = 0 maximum = 0 for num in nums: maximum = max(maximum, num) ans += maximum - num print(ans)
p02578
s815396100
Accepted
n=int(input()) l=list(map(int, input().split())) a=0 for i in range(n-1): if l[i]>l[i+1]: a=a+l[i]-l[i+1] l[i+1]=l[i] print(a)
p02578
s045792235
Accepted
import sys n=int(input()) li=[int(x) for x in input().split()] h=0 k=0 for i in range(n): if h<=li[i]: h=max(h,li[i]) else: k=k+(h-li[i]) h=max(h,li[i]) print(k)
p02578
s854571497
Accepted
N = int(input()) N_List = list(map(int,input().split())) ct = 0 for i in range(1,N): if N_List[i] < N_List[i-1]: ct += N_List[i-1] - N_List[i] N_List[i] = N_List[i-1] print(ct)
p02578
s398128222
Accepted
n = int(input()) num = list(map(int,input().split())) ans = 0 m = num[0] for i in range(1,n): if m >= num[i]: ans += m - num[i] else: m = num[i] print(ans)
p02578
s840150164
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 cur_max=0 for x in a: if cur_max > x: ans += cur_max - x cur_max = max(cur_max, x) print(ans)
p02578
s329393064
Accepted
# -*- coding: utf-8 -*- def main(): N = int(input()) A = [int(i) for i in input().split()] ans = 0 max = A[0] for a in A: if max > a: ans += max-a else: max = a print(ans) if __name__ == "__main__": main()
p02578
s435957009
Accepted
n = int(input()) A = [0]+list(map(int,input().split())) ans = 0 for i in range(1,n+1): d = A[i-1] -A[i] if(d >0): A[i] += d ans += d print(ans)
p02578
s613971852
Accepted
# C - Step from itertools import accumulate import operator n = int(input()) a = list(map(int, input().split())) assert n == len(a) b = accumulate(a, max) s = sum(map(operator.sub, b, a)) print(s)
p02578
s097332289
Accepted
N = int(input()) A = [int(x) for x in input().split()] total = 0 for i in range(1, N): d = max(A[i-1] - A[i], 0) A[i] += d total += d print(total)
p02578
s221765510
Accepted
n = int(input()) l = list(map(int, input().split())) maxNum = l[0] total = 0 for i in range(1,len(l)): if maxNum <= l[i]: maxNum = l[i] else: total += maxNum - l[i] print(total)
p02578
s773963900
Accepted
n = int(input()) a = list(map(int,input().split())) ans = 0 for i in range(1,n): dif = a[i] - a[i-1] if dif<0: a[i] -= dif ans -= dif print(ans)
p02578
s567619457
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 maxA = A[0] for i in range(1,N): if A[i] > maxA: maxA = A[i] else: ans = ans + maxA - A[i] print(ans)