problem_id stringclasses 100
values | submission_id stringlengths 10 10 | status stringclasses 2
values | code stringlengths 6 806 |
|---|---|---|---|
p02578 | s074189866 | Accepted | N = int(input())
A = list(map(int,input().split()))
now_max = A[0]
ans = 0
for i in range(N):
if A[i] > now_max:
now_max = A[i]
else:
ans += now_max - A[i]
print(ans) |
p02578 | s286172833 | Accepted | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
n = I()
a = LI()
bemax = a[0]
ans = 0
for i in a[1:]:
if i > bemax:
bemax = i
elif i < bemax:
ans += bemax - i
print(ans)
main() |
p02578 | s633083972 | Accepted | n = int(input())
a = list(map(int,input().split()))
hight_sum = 0
for i in range(n-1):
hight = 0
diff = a[i+1] - a[i]
if diff < 0:
hight -= diff
a[i+1] -= diff
hight_sum += hight
print(hight_sum) |
p02578 | s720087665 | Accepted | import sys
readline = sys.stdin.buffer.readline
N = int(readline())
A = list(map(int, readline().split()))
ans = 0
height = A[0]
for i in range(1, N):
h = A[i]
if h < height:
ans += height - h
height = max(height, h)
print(ans)
|
p02578 | s501363924 | Accepted | N=input()
*A, = map(int,input().split())
ans = 0
h = A[0]
for a in A:
ans += max(0,h-a)
h = max(h,a)
print(ans) |
p02578 | s755543753 | Accepted | N = int(input())
A = list(map(int, input().split()))
pre_max = 0
ans = 0
for An in A:
if pre_max <= An:
pre_max = An
else:
ans += pre_max - An
print(ans) |
p02578 | s623614349 | Accepted | n=int(input())
a=list(map(int, input().split()))
fumidai=fumidau=0
try:
for i in range(len(a)):
kijun=a[i]
if kijun>a[i+1]:
fumidau=kijun-a[i+1]
fumidai+=fumidau
a[i+1]=a[i+1]+fumidau
except:
pass
print(fumidai) |
p02578 | s380930183 | Accepted | n = int(input())
a = list(map(int, input().split()))
maxx, h = 0, 0
for i in range(n):
maxx = max(maxx, a[i])
h += maxx - a[i]
print(h) |
p02578 | s177564505 | Accepted | N = int(input())
array = list(map(int,input().split()))
d,f = 0,array[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)
if n > f:
f = n
print( sum(ans) )
|
p02578 | s544193680 | Accepted | N = int(input())
A = [int(i) for i in input().split()]
K = 0
for i in range(N-1):
if A[i] > A[i+1]:
S = A[i] - A[i+1]
# リストの前の最大値を取得して比較しないといけない。
A[i+1] += S
K += S
else:
pass
print(K) |
p02578 | s091329762 | Accepted | n = int(input())
an = [int(num) for num in input().split()]
sum = 0
for i in range(len(an)-1):
if an[i] > an[i+1]:
sum += an[i] - an[i+1]
an[i+1] += an[i] - an[i+1]
print(sum) |
p02578 | s000622836 | Accepted | n = int(input())
line=list(map(int,input().split( )))
step_sum=0
h=line[0]
for i in line:
if i<h:
step_sum+=h-i
elif i>h:
h=i
print(step_sum) |
p02578 | s320955947 | Accepted | b=s=0
for a in[*open(0)][1].split():a=int(a);b=max(b,a);s+=b-a
print(s) |
p02578 | s011223033 | Accepted | if __name__ == '__main__':
n = int(input())
A = list(map(int,input().split()))
top = A[0]
ans = 0
for i in range(n-1):
if top > A[i+1]:
ans += top - A[i+1]
else:
top = A[i+1]
print(ans) |
p02578 | s912345076 | Accepted | n=int(input())
a=list(map(int,input().split()))
maxa=0
total=0
for i in a:
maxa=max(maxa,i)
total=total+maxa-i
print(total) |
p02578 | s214774646 | Accepted | n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
if a[i+1]<a[i]:
t=a[i]-a[i+1]
s+=t
a[i+1]+=t
print(s)
|
p02578 | s142160133 | Accepted | n = int(input())
a = list(map(int, input().split()))
highest, ans = 0, 0
for l in a:
if highest > l:
ans += highest - l
elif highest < l:
highest = l
else:
pass
print(ans) |
p02578 | s149523761 | Accepted | N = int(input())
A = [int(i) for i in input().split()]
max = 0
sum = 0
for a in A:
if a < max:
sum += max - a
if a > max:
max = a
print(sum) |
p02578 | s351655964 | Accepted | n=int(input())
a=list(map(int, input().split()))
curr=a[0]
ans=0
for i in range(n):
if a[i]<curr:
ans+=(curr-a[i])
else:
curr=max(curr, a[i])
print(ans) |
p02578 | s578085347 | Accepted | num = int(input())
height = input().split()
sum = 0
max_height_now = 0
for index in range(num):
height_now = int(height[index])
if height_now >= max_height_now:
max_height_now = height_now
else:
sum += max_height_now - height_now
print(sum) |
p02578 | s218552813 | Accepted | # vim: fileencoding=utf-8
def main():
n = int(input())
li = list(map(int, input().split()))
max = 0
total = 0
for i in li:
if max < i:
max = i
continue
elif max == i:
continue
else:
total += max - i
print(total)
if __name__ == "__main__":
main()
|
p02578 | s159413741 | Accepted | n = int(input())
a = list(map(int, input().split()))
mae = a[0]
ans = 0
for i in a:
if mae > i:
ans += mae - i
else:
mae = i
print(ans)
|
p02578 | s117974899 | Accepted | n=int(input())
alist=list(map(int,input().split()))
height=alist[0]
ans=0
for i in range(1,n):
if height>alist[i]:
ans+=height-alist[i]
else:
height=alist[i]
print(ans) |
p02578 | s377915170 | Accepted | n = int(input())
arr = [int(j) for j in input().split()]
ans = 0
for i in range(1, n):
ans += max(0, arr[i-1] - arr[i])
if arr[i-1] > arr[i]:
arr[i] = arr[i-1]
print(ans)
|
p02578 | s115123610 | Accepted | def step(arr):
res = 0
for i in range(1,len(arr)):
if arr[i] >= arr[i-1]:
continue
else:
res += abs(arr[i-1] - arr[i])
arr[i] = arr[i - 1]
return res
def start():
n = int(input())
arr = [int(x) for x in input().split(" ")]
print(step(arr))
start() |
p02578 | s083588651 | Accepted | N = int(input())
A = list(map(int, input().split()))
hight = A[0]
k = 0
for i in range(1, N):
if hight > A[i]:
k += (hight - A[i])
else:
hight = A[i]
print(k) |
p02578 | s858167949 | Accepted | n = int(input())
num_list = [int(i) for i in input().split()]
count = 0
for i in range(1,n):
if num_list[i] < num_list[i-1]:
count += (num_list[i-1] - num_list[i])
num_list[i] = num_list[i-1]
print(count) |
p02578 | s934266438 | Accepted | n = int(input())
a = [int(i) for i in input().split()]
m = a[0]
sum = 0
for i in a[1:]:
if i <= m:
sum += m - i
else:
m = i
print(sum) |
p02578 | s368496613 | Accepted | n=int(input(""))
lisa=input("").split(" ")
t=0
s=int(lisa[0])
for i in lisa:
if(s<int(i)):
s=int(i)
else:
t+=s-int(i)
print(t) |
p02578 | s834773214 | Accepted | N = input()
A = map(int, input().split())
current = 0
ans = 0
for a in A:
ans += current - min(current, a)
current = max(current, a)
print(ans) |
p02578 | s119727384 | Accepted | 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]
A[i+1] += a
result += a
print(result) |
p02578 | s956667045 | Accepted | N = int(input())
A = list(map(int,input().split()))
H = 0
for i in range(1,N):
if A[i] < A[i-1]:
sa = A[i-1] - A[i]
A[i] = A[i-1]
H += sa
print(H) |
p02578 | s218088382 | Accepted | n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(1,n):
d=A[i-1]-A[i]
if d>0:
ans += d
A[i]+=d
print(ans) |
p02578 | s743039145 | Accepted | n=int(input())
l=list(map(int,input().split()))
ans = 0
for i in range(n):
if i > 0 and l[i] < l[i-1]:
ans += l[i-1] - l[i]
l[i] = l[i-1]
print(ans) |
p02578 | s183193403 | Accepted | def main():
N = int(input())
A = list(map(int, input().split()))
temp = A[0]
su = 0
for i in range(1, N):
if A[i - 1] > A[i]:
su += A[i - 1] - A[i]
A[i] = A[i - 1]
print(su)
if __name__ == '__main__':
main()
|
p02578 | s177052328 | 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 | s533818792 | Accepted | import numpy as np
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(input())
A_str = input()
A_lst = A_str.split(" ")
A_lst = [int(A_lst[i]) for i in range(N)]
dai_lst = []
tmp = A_lst[0]
for a in A_lst:
if a<tmp:
dai_lst.append(tmp-a)
elif a>tmp:
tmp = a
out = sum(dai_lst)
print(out) |
p02578 | s357551418 | Accepted | from sys import stdin
import math
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
ans = 0
for i in range(1, n):
if a[i] < a[i-1]:
ans += a[i-1] - a[i]
a[i] += a[i-1] - a[i]
print(ans) |
p02578 | s142011817 | Accepted | N = int(input())
A = list(map(int,input().split()))
step = 0
height = 0
for i in range(N):
if A[i] <= height:
step += height - A[i]
else:
height = A[i]
print(step) |
p02578 | s106478618 | Accepted | 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 - 1] - a[i]
a[i] = a[i - 1]
print(ans)
|
p02578 | s359567841 | Accepted | 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)
|
p02578 | s653220326 | Accepted | n = int(input())
a = [int(i) for i in input().split()]
h = 0
c = 0
for ai in a:
if ai < h:
c += h - ai
h = max(ai, h)
print(c) |
p02578 | s493544802 | Accepted | n = int(input())
aa = list(map(int, input().split()))
amax = aa[0]
total = 0
for a in aa:
amax = max(amax,a)
total += (amax - a)
print(total)
|
p02578 | s196756721 | Accepted | n = int(input())
a = list(map(int,input().split()))
x = 0
total = 0
for i in range(n-1):
if a[i] >= a[i+1]:
x = a[i] - a[i+1]
total += x
a[i+1] = a[i]
i = i+1
else:
total += 0
print(total) |
p02578 | s281510021 | Accepted | n = int(input())
a = list(map(int,input().split()))
m = a[0]
s = 0
for i in range(1,n):
m = max(m,a[i])
s += m-a[i]
print(s) |
p02578 | s530921030 | Accepted | N = int( input() )
A = list( map( int, input().split() ))
ret = 0
bafore = A[0]
for a in A:
if bafore > a:
ret += bafore - a
bafore = max( a, bafore )
print( ret ) |
p02578 | s962430008 | Accepted | N= int(input())
A = list(map(int, input().split()))
res = 0
current = A[0]
for i in range(1, N):
res += (current - A[i]) if current > A[i] else 0
current = current if current > A[i] else A[i]
print(res) |
p02578 | s093074890 | Accepted | n = int(input())
num_list = list(map(int, input().split()))
a = int(num_list[0])
p = 0
for i in range(n):
if num_list[i] < a:
p = p + (a - num_list[i])
elif num_list[i] > a:
a = num_list[i]
print(p) |
p02578 | s043410964 | Accepted | N = int(input())
A = list(map(int, input().split()))
ans = 0
height = A[0]
for i in range(1, N):
if A[i]<height:
ans += height-A[i]
elif A[i]>A[i-1]:
height = A[i]
print(ans) |
p02578 | s201687085 | Accepted | N = int(input())
height = [int(i) for i in input().split()]
step = 0
for i, h in enumerate(height):
if i == 0:
pre = h
else:
if h < pre:
step += (pre - h)
pre = pre
else:
step += 0
pre = h
print(step) |
p02578 | s526515814 | Accepted | n = int(input())
As = list(map(int, input().split()))
mx = 0
ans = 0
for a in As:
if mx < a:
mx = a
else:
ans += mx - a
print(ans) |
p02578 | s322211792 | Accepted | n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(n-1):
if a[i] > a[i+1]:
b = a[i] - a[i+1]
a[i+1] += b
sum += b
print(sum) |
p02578 | s789493949 | Accepted | n=int(input())
li = list(map(int,input().split()))
now=li[0]
sum=0
for i in li[1:]:
if now>i:
sum+=now-i
elif i>now:
now=i
print(sum)
|
p02578 | s622028652 | Accepted | def solve(n, arr):
ans_arr = [0]
for i in range(0, n-1):
if arr[i] > arr[i + 1]:
diff = arr[i] - arr[i + 1]
ans_arr.append(diff)
arr[i + 1] += diff
else:
ans_arr.append(0)
return sum(ans_arr)
if __name__ == "__main__":
n = int(input())
arr = list(map(int, input().split(' ')))
print(solve(n, arr)) |
p02578 | s611120550 | Accepted | N=int(input())
A=list(map(int,input().split()))
ans=0
mx=0
for x in A:
if mx>=x:
ans+=mx-x
else:
mx=x
print(ans)
|
p02578 | s505804778 | Accepted | n=int(input())
A = list(map(int,input().split()))
max_value = max(A)
max_index = A.index(max_value)
c=0
for i in range(max_index,n):
c+=(max_value-A[i])
for i in range(1,max_index):
if A[i-1]>A[i]:
c+=(A[i-1]-A[i])
A[i]=A[i-1]
print(c) |
p02578 | s335625223 | Accepted | def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
a = intl()
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] - a[i])
print(ans) |
p02578 | s311103905 | Accepted | n = int(input())
a = list(map(int, input().split()))
ans = 0
chk = a[0]
for x in a[1:]:
if chk > x:
ans += chk - x
else:
chk = x
print(ans)
|
p02578 | s701395823 | Accepted | #!/usr/bin/env python
from typing import List
def f(n: int, a_list: List[int]) -> int:
"""
>>> f(5, [2, 1, 5, 4, 3])
4
"""
ans = 0
n_max: int = a_list[0]
for i, a_i in enumerate(a_list):
if n_max > a_i:
ans += n_max - a_i
else:
n_max = a_i
return ans
if __name__ == '__main__':
n = int(input())
a_list = list(map(lambda x: int(x), input().split()))
print(f(n, a_list)) |
p02578 | s375013974 | Accepted | N, *A = map(int, open(0).read().split())
result = 0
p = A[0]
for i in range(1, N):
if p >= A[i]:
result += p - A[i]
else:
p = A[i]
print(result)
|
p02578 | s304129145 | Accepted | INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
n=INT()
A=LIST()
ans=0
mina=0
for a in A:
mina=max(mina,a)
ans+=max(0,mina-a)
print(ans)
if __name__ == '__main__':
do() |
p02578 | s524787941 | Accepted | N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(len(L) - 1):
if L[i] - L[i + 1] >= 0:
ans = ans + L[i] - L[i + 1]
L[i + 1] = L[i]
print(ans) |
p02578 | s506511872 | Accepted | n = int(input())
a = list(map(int, input().split()))
ans = 0
highest = a[0]
for ai in a:
if ai <= highest:
ans += highest - ai
else:
highest = ai
print(ans)
|
p02578 | s958727373 | Accepted | N = int(input())
A = list(map(int,input().split()))
hight = A[0]
base = 0
for i in range(1,N):
if A[i] < hight:
base += hight - A[i]
else:
hight = A[i]
print(base) |
p02578 | s230747538 | Accepted | N = input()
AL = list(map(int,input().split()))
Amax = 0
FD = 0
for Ai in AL:
# print('FD=%d' % FD)
if Amax > Ai:
# print('1')
FD = FD + (Amax - Ai)
elif Amax < Ai:
# print('2')
Amax = Ai
print(FD) |
p02578 | s843763831 | Accepted | N=int(input())
A=list(map(int,input().split()))
H=A[0]
ans=0
for i in range(N):
ans+=max(0,(H-A[i]))
H=max(H,A[i])
#print(H)
print(ans) |
p02578 | s639034938 | Accepted | import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
if N == 1:
print(0)
else:
x = 0
for i in range(0,len(L)-1):
if L[i] > L[i + 1]:
x = x + (L[i] - L[i + 1])
L[i + 1] = L[i + 1] + (L[i] - L[i + 1])
print(x)
|
p02578 | s989562983 | Accepted | 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) |
p02578 | s798902199 | Accepted | try:
k = int(input())
l = list(map(int,input().split(' ')))
c = 0
for i in range(len(l)-1):
x = l[i+1]-l[i]
if x<0:
l[i+1]+=abs(x)
c+=abs(x)
print(c)
except:
pass
|
p02578 | s718670698 | Accepted | N = int(input())
A = map(int, input().split())
A = list(A)
stage_hight = []
for i, ai in enumerate(A):
if i != 0 and ai < A[i-1]:
stage_hight.append(A[i-1] - ai)
A[i] = A[i-1]
print(sum(stage_hight))
|
p02578 | s294114333 | Accepted | 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
else:
m = a[i]
print(ans)
|
p02578 | s475421684 | Accepted | n = int(input())
p = list(map(int, input().split()))
a = 0
for i in range(1,n):
if p[i-1] > p[i]:
a = a + p[i-1] - p[i]
p[i] = p[i-1]
else:
p[i] = p[i]
a = a
print(a) |
p02578 | s970012955 | Accepted | N=int(input())
A=[int(i) for i in input().split()]
ans=0
for i in range(1,N):
if A[i]<A[i-1]:
ans+=A[i-1]-A[i]
A[i]=A[i-1]
print(ans)
|
p02578 | s790196786 | Accepted | n = int(input())
a = list(map(int,input().split()))
cnt = 0
mx = a[0]
for i in range(1,n):
if a[i] > mx:
mx = a[i]
if a[i] < mx:
cnt = cnt + (mx - a[i])
print(cnt) |
p02578 | s810012959 | Accepted | n = int(input())
a = [int(i) for i in input().split()]
c = 0
t = a[0]
for i in a:
if t>i:
b=t-i
c+=b
else:
t=i
print(c) |
p02578 | s080192914 | Accepted | n = int(input())
a = list(map(int, input().split()))
max_num = 0
step = []
for i in range(n):
if a[i] >= max_num:
max_num = a[i]
else:
step.append(max_num - a[i])
print(sum(step))
|
p02578 | s030440115 | Accepted | n = int(input())
a = list(map(int,input().split(" ")))
answer = 0
for i in range(1,n):
if a[i] < a[i - 1]:
answer += a[i-1] - a[i]
a[i]= a[i - 1]
print(answer) |
p02578 | s724328432 | Accepted | N=int(input())
A=list(map(int,input().split()))
m=0
K=0
for i in range(N):
if i==0:
m=A[i]
else:
S=max(0,m-A[i])
K+=S
m=A[i]+S
print(K)
|
p02578 | s704743706 | Accepted | n = int(input())
a = list(map(int,input().split())) + [0]
ans = 0
maxh = a[0]
for i in range(n):
if maxh > a[i]:
ans += maxh - a[i]
a[i] = maxh
else:
maxh = a[i]
print(ans) |
p02578 | s174748764 | Accepted | n=int(input())
a=list(map(int,input().split()))
b=a
s=0
for i in range(n-1):
if b[i]>a[i+1]:
s+=(a[i]-a[i+1])
b[i+1]=b[i]
print(s) |
p02578 | s476745628 | Accepted | n = int(input())
a = list(map(int, input().split( )))
front = 0
step = 0
for height in a :
x = 0
if front > height :
x = front - height
step += x
if front < height:
front = height
print(step)
|
p02578 | s986493283 | Accepted | import heapq
import math
def main():
N = input()
A = list(map(int, input().split()))
res = 0
max_a = A[0]
for a in A[1:]:
if max_a > a:
res += (max_a - a)
else:
max_a = a
print(res)
if __name__ == "__main__":
main() |
p02578 | s722412896 | Accepted | N = int(input())
A = list(map(int, input().split()))
step = [0] * N
for i, a in enumerate(A[1:], 1):
step[i] = max(0, A[i - 1] + step[i - 1] - a)
print(sum(step)) |
p02578 | s034759525 | Accepted | n=int(input())
l=list(map(int,input().split()))
ans=0
m=l[0]
for i in l[1:]:
if i<m:
ans+=m-i
else:
m=i
print(ans) |
p02578 | s146699499 | Accepted | def main():
N = int(input())
A = list(map(int, input().split()))
m = A[0]
S = 0
for a in A:
if m - a > 0:
S += m - a
if m < a:
m = a
print(S)
if __name__ == "__main__":
main()
|
p02578 | s635129600 | Accepted | #!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
N = int(input())
A = list(map(int, input().split()))
ans = 0
prev = None
for a in A:
if prev is None:
prev = a
continue
if prev > a:
diff = prev - a
else:
diff = 0
ans += diff
prev = a + diff
print(ans)
|
p02578 | s806655689 | Accepted | 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] = A[i-1]
print(sum) |
p02578 | s646745377 | Accepted | 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-1]-A[i]
A[i] = A[i-1]
print(ans) |
p02578 | s057533864 | Accepted | N = int(input())
As = list(map(int, input().split()))
sum_humidai = 0
max_front_person = 0
for person_idx, person_height in enumerate(As):
if person_idx == 0:
continue
max_front_person = max(max_front_person, As[person_idx - 1])
if max_front_person > person_height:
humidai = max_front_person - person_height
sum_humidai += humidai
print(sum_humidai) |
p02578 | s003867472 | Accepted | N = int(input())
A = list(map(int, input().split()))
sum_value = 0
for i in range(len(A)-1):
if A[i] >= A[i+1]:
x = A[i] - A[i+1]
A[i+1] = x + A[i+1]
sum_value += x
print(sum_value) |
p02578 | s884255845 | Accepted | from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def main():
n = ri()
A = ril()
h = 0
ans = 0
for a in A:
dh = max(h-a, 0)
h = a + dh
ans += dh
print(ans)
if __name__ == '__main__':
main()
|
p02578 | s248910629 | Accepted | n=int(input())
lst=list(map(int,input().split()))
_max=lst[0]
st=0
for i in lst:
if i>=_max:
_max=i
else:
st=st+(_max-i)
print(st) |
p02578 | s792943035 | Accepted | N = int(input())
A = list(map(int, input().split()))
cnt = 0
if N == 1:
print(0)
exit()
for i in range(1, N):
if A[i] >= A[i - 1]:
continue
else:
cnt += A[i - 1] - A[i]
A[i] = A[i - 1]
print(cnt)
|
p02578 | s387785474 | Accepted | n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(n-1):
dif = A[i] - A[i+1]
if dif > 0:
A[i+1] += dif
ans += dif
print(ans) |
p02578 | s613013335 | Accepted | n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(1,n):
if a[i]<a[i-1]:
cnt+=a[i-1]-a[i]
a[i]=a[i-1]
cnt+=a[i-1]-a[i]
print(cnt) |
p02578 | s898736544 | Accepted | n=int(input())
a=list(map(int,input().split()))
ans=0
max=a[0]
for i in range(1,n):
if max>a[i]:
ans+=max-a[i]
else:
max=a[i]
print(ans) |
p02578 | s140317505 | Accepted | 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-1]-a[i]
a[i]=a[i-1]
print(ans) |
p02578 | s191648393 | Accepted | N=int(input())
A=list(map(int,input().split()))
M=0
P=0
for i in range(N):
P+=max(0,M-A[i])
M=max(M,A[i])
print(P)
|
p02578 | s991459411 | Accepted | n = int(input())
a = list(map(int,input().split()))
before_max = a[0]
humidai = 0
humidai_sum = 0
for i in range(1,n):
humidai = 0
if(before_max >= a[i]):
humidai = before_max - a[i]
humidai_sum += humidai
if(before_max < a[i]):
before_max = a[i]
#print(humidai,before_max,before_max)
print(humidai_sum) |
p02578 | s341440754 | Accepted | n=int(input())
a=list(map(int,input().split()))
ans=0
maenomax=a[0]
for i in range(n):
if maenomax > a[i]:
ans += maenomax-a[i]
elif maenomax < a[i]:
maenomax=a[i]
print(ans) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.