problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02578
s666716560
Accepted
def readinput(): n=int(input()) a=list(map(int,input().split())) return n,a def main(n,a): sum=0 h=a[0] for i in range(1,n): if h>a[i]: sum+=h-a[i] else: h=a[i] return sum if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
p02578
s601403731
Accepted
N = int(input()) A = list(map(int, input().split())) step_sum = 0 for i in range(1, N): if A[i - 1] > A[i]: step = A[i - 1] - A[i] A[i] += step step_sum += step print(step_sum)
p02578
s776392953
Accepted
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split(' '))) ans = [] for i in range(N): if i == 0: ans.append(0) else: h = A[i-1] - A[i] if h < 0: ans.append(0) else: ans.append(h) A[i] += h print(sum(ans))
p02578
s739818655
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
s889544224
Accepted
n = int(input()) A = list(map(int, input().split())) highest = 0 ans = 0 for a in A: if a >= highest: highest = a else: ans += highest - a print(ans)
p02578
s495454590
Accepted
max_height = 0 step_sum = 0 input() people_height_array = map(int, input().split()) for height in people_height_array: if max_height <= height: max_height = height else: step_sum += max_height - height print(step_sum)
p02578
s948631015
Accepted
N=int(input()) A=list(map(int,input().split())) sum=0 MaxNum=0 for i in range(N): MaxNum=max(MaxNum,A[i]) B=MaxNum sum+=MaxNum-A[i] print(sum)
p02578
s976596744
Accepted
n = int(input()) a = list(map(int, input().split())) num = 0 s = a[0] for i in range(1,n): if s <= a[i]: s = a[i] else: num += (s-a[i]) print(num)
p02578
s895188276
Accepted
N = int(input()) A = list(map(int, input().split())) cnt = 0 prv = 0 for i in range(N): now = A[i] if prv > now: cnt += prv - now else: prv = now print(cnt)
p02578
s744327475
Accepted
n,p,*v=map(int,open(0).read().split()) a=0 for t in v: if p>t:a+=p-t else:p=t print(a)
p02578
s710343212
Accepted
N = int(input()) A = list(map(int,input().split())) ans = 0 if N == 1: print(ans) else: tmp_max = A[0] for a in A[1:]: if a < tmp_max: ans += tmp_max-a else: tmp_max = a print(ans)
p02578
s223596888
Accepted
# coding: utf-8 import math num = int(input()) total = 0 max = 0 tall = list(map(int, input().split())) for i in range(num): if max <= tall[i]: max = tall[i] if max > tall[i]: total += max -tall[i] print(total)
p02578
s415765566
Accepted
#!/usr/bin/env python3 input() A = list(map(int, input().split())) front_height = A[0] ret = 0 for a in A[1:]: if a < front_height: ret += front_height - a front_height = max(front_height, a) print(ret)
p02578
s016846812
Accepted
n = int(input()) A = list(map(int, input().split())) out = 0 t_h = A[0] for i in A: a = max(t_h - i, 0) out += a t_h = i + a print(out)
p02578
s356935797
Accepted
n = int(input()) x = list(map(int, input().split())) result = 0 for i in range(n - 1): if x[i] > x[i + 1]: result += (x[i] - x[i + 1]) x[i + 1] = x[i] print(result)
p02578
s106957668
Accepted
n = int(input()) a = [int(i) for i in input().split()] ans=0 for i in range(1,n): d = a[i-1] - a[i] if d>0: ans+= d a[i]=a[i]+d else: continue print(abs(ans))
p02578
s185858923
Accepted
N = int(input()) L = list(map(int, input().split())) count = 0 for i in range(N-1): if L[i] > L[i + 1]: difference = L[i] - L[i + 1] L[i+1] += difference count += difference print(count)
p02578
s098184856
Accepted
N = int(input()) A = list(map(int, input().split())) ans, pre = 0, A[0] for i in range(1, N): ans += max(0, pre-A[i]) pre = max(pre, A[i]) print(ans)
p02578
s084599499
Accepted
n = int(input()) a = list(map(int,input().split())) a_max = max(a) 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
s962533569
Accepted
N = int(input()) A = list(map(int,input().split())) T = 0 ans = 0 for i in range(N): if A[T] >= A[i]: ans += A[T] - A[i] else: T = i print(ans)
p02578
s833201182
Accepted
N = int(input()) A = [int(_) for _ in input().split()] ans = 0 v = A[0] for a in A: if a < v: ans += v - a v = max(v, a) print(ans)
p02578
s281440365
Accepted
n=int(input()) a=[int(x) for x in input().split()] sum=0 for i in range(len(a)-1): if a[i]>a[i+1]: sum+=a[i]-a[i+1] a[i+1]=a[i] print(sum)
p02578
s938120189
Accepted
N = int(input()) A = list(map(int, input().split())) maxtall = A[0] ans = 0 for i in range(1, N): if A[i] < maxtall: ans += maxtall - A[i] elif A[i] > maxtall: maxtall = A[i] print(ans)
p02578
s901543760
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 m = a[0] for i in range(1, n): ans += max(m - a[i], 0) m = max(m, a[i]) print(ans)
p02578
s525460015
Accepted
N = int(input()) a = list(map(int,input().split())) sum = 0 for n in range(N-1): if a[n] > a[n+1]: dif = a[n] - a[n+1] a[n+1] = a[n+1] + dif sum += dif print(sum)
p02578
s623966062
Accepted
N = int(input()) A = list(map(int, input().split())) count=0 for n in range(1,N): if A[n]<A[n-1]: H = A[n-1]-A[n] count+=H A[n]=A[n-1] print(count)
p02578
s714808404
Accepted
n = int(input()) A = list(map(int,input().split())) pre = A[0] ans = 0 for a in A: if pre > a: ans += pre - a pre = pre else: pre = a print(ans)
p02578
s360274614
Accepted
n = int(input()) strNums = input().split() intNums = [int(i) for i in strNums] step = [] initialValue = intNums[0] for i in range(len(intNums)): if intNums[i] < initialValue: step.append(initialValue - intNums[i]) else: step.append(0) initialValue = intNums[i] print(sum(step))
p02578
s444053043
Accepted
n = int(input()) m = list(map(int,input().split())) count = 0 for i in range(n-1): if m[i]<=m[i+1]: pass else: s = m[i]-m[i+1] m[i+1]=m[i+1]+s count = count + s print(count)
p02578
s810796645
Accepted
n=int(input()) s=list(map(int,input().split())) ans=0 for i in range(n-1): ans+=max(s[i]-s[i+1],0) s[i+1]=max(s[i+1],s[i]) print(ans)
p02578
s116685280
Accepted
N = int(input()) As = list(map(int, input().split())) now = 0 cost = 0 for A in As: if A > now: now = A else: cost += now-A print(cost)
p02578
s877599431
Accepted
N = int(input()) a = [int(s) for s in input().split()] b = int(0) for i in range(N-1): if a[i] <= a[int(i+1)]: pass else: b = b + (a[i] - a[int(i+1)]) a[int(i+1)] = a[i] print(b)
p02578
s942942119
Accepted
input_n = input() N = str(input_n) input_a = input() A = str(input_a) listN = A.split(' ') listA = [] for value in range(len(listN)): listA.append(int(listN[value])) result = 0 for value in range(1, len(listA)): if listA[value] < listA[value - 1]: result += (int(listA[value - 1]) - int(listA[value])) listA[value] += (int(listA[value - 1]) - int(listA[value])) print(str(result))
p02578
s440261843
Accepted
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() A=LI() ans=0 ceil=A[0] for i in range(N): if A[i]>ceil: ceil=A[i] else: ans+=ceil-A[i] print(ans) main()
p02578
s445457745
Accepted
n=int(input()) a=list(map(int, input().split())) m=0 ans=0 for i in a: if m>i: ans+=m-i else: m=i print(ans)
p02578
s340052474
Accepted
n = int(input()) a = list(map(int, input().split())) highest = 0 ans = 0 for i in a: if i > highest: highest = i ans += highest - i print(ans)
p02578
s628214137
Accepted
def resolve(): N = int(input()) A = list(map(int,input().split())) sm =0 for i in range(1,N): if A[i]<A[i-1]: sm += A[i-1]-A[i] A[i]=A[i-1] print(sm) resolve()
p02578
s324968990
Accepted
N = int(input()) A = list(map(int, input().split())) cnt = 0 for i in range(N-1): if A[i] > A[i+1]: cnt += A[i] - A[i+1] A[i+1] += A[i] - A[i+1] print(cnt)
p02578
s127987649
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
s029245769
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
s868040960
Accepted
n = int(input()) a = list(map(int, input().split())) tmp = a[0] ans = 0 for i in a[1:]: if tmp > i: ans += tmp - i else: tmp = i print(ans)
p02578
s301252338
Accepted
n = int(input()) a = list(map(int,input().split())) c = 0 for i in range(1,n): if a[i-1]>a[i]: q = (a[i-1]-a[i]) c += q a[i] = a[i]+q print(c)
p02578
s118186691
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 mx_a = a[0] for i in range(n): if mx_a > a[i]: ans += mx_a - a[i] mx_a = max(mx_a, a[i]) print(ans)
p02578
s596822318
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
s662512963
Accepted
# -*- coding: utf-8 -*- 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
s284426123
Accepted
import sys def main(): input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) ans = 0 forward = 0 for i in range(n): if a[i] < forward: ans += forward - a[i] else: forward = a[i] print(ans) if __name__ == "__main__": main()
p02578
s095436902
Accepted
N = int(input()) A = list(map(int,input().split())) num_b = 0 cnt = 0 for i in A: if num_b > i: cnt += num_b - i else: num_b = i print(cnt)
p02578
s746955531
Accepted
N = int(input()) A = list(map(int, input().split())) step = 0 before_max = A[0] for i in range(1, N): if (A[i] >= before_max): before_max = A[i] else: step += before_max - A[i] print(step)
p02578
s528003951
Accepted
N = int(input()) A = list(map(int,input().split())) a = 0 for i in range(N - 1): if A[i] > A[i + 1]: a += A[i] - A[i + 1] A[i + 1] = A[i] print(a)
p02578
s888780753
Accepted
n=int(input()) p=list(map(int,input().split())) ans=0 for i in range(1,len(p)): if p[i]<p[i-1]: ans+=p[i-1]-p[i] p[i]=p[i-1] print(ans)
p02578
s842081223
Accepted
input() b=list(map(int,input().split())) ans=0 tall=0 for i in b: if tall>i: ans+=tall-i else: tall=i print(ans)
p02578
s005457745
Accepted
N = int(input()) A = list(map(int,input().split())) ans = 0 maximum = A[0] for i in range(1,N): if A[i] < maximum: ans += (maximum - A[i]) else: maximum = A[i] print(ans)
p02578
s767628009
Accepted
# coding:utf-8 n = int(input()) a = list(map(int, input().split())) ans = 0 tall = 0 for i in range(n): if a[i] < tall: ans += tall - a[i] else: tall = a[i] print(ans)
p02578
s889517497
Accepted
N = int(input()) As = list(map(int, input().split())) b = As[0] rlt = 0 for i in range(1,N): if b > As[i]: rlt += b-As[i] else: b = As[i] print(rlt)
p02578
s712500580
Accepted
N = int(input()) A = [int(s) for s in input().split()] ma = A[0] total = 0 for a in A: if a < ma: total += ma - a ma = max(ma, a) print(total)
p02578
s991781390
Accepted
n=int(input()) l=list(map(int,input().split())) sum=0 m=l[0] for i in range(1,n): m=max(m,l[i]) sum+=m-l[i] print(sum)
p02578
s275978016
Accepted
N = int(input()) A = [int(a) for a in input().split(" ")] ans = 0 for i in range(len(A)): if i == 0: continue else: if A[i] < A[i - 1]: ans += A[i - 1] - A[i] A[i] = A[i - 1] print(ans)
p02578
s115637847
Accepted
n = int(input()) a = list(map(int, input().split())) h = 0 for i in range(1, len(a)): abs = a[i-1] - a[i] if(abs > 0): h += abs a[i] = a[i-1] print(h)
p02578
s110631549
Accepted
n = int(input()) a_list = list(map(int, input().split())) result = [0] for i in range(n - 1): if a_list[i] + result[i] > a_list[i + 1]: result.append(a_list[i] + result[i] - a_list[i + 1]) else: result.append(0) print(sum(result))
p02578
s791736332
Accepted
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 += pre - now pre = now + (pre - now) else: pre = now print(ans)
p02578
s596193162
Accepted
n = int(input()) A = list(map(int, input().split())) ans = 0 prev = 0 for a in A: if prev <= a: prev = a continue ans += prev - a print(ans)
p02578
s549790713
Accepted
N = int(input()) A = map(int , input().split()) B = [] flg = True before = 0 for a in A: if flg: flg = False B.append(0) before = a else: add = max(before - a, 0) B.append(add) before = a + add print(sum(B))
p02578
s825676760
Accepted
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] n = inp() x = ip() mx = 0 ans = 0 for i in x: mx = max(mx,i) ans += mx-i print(ans)
p02578
s628270155
Accepted
n = int(input()) a = list(map(int, input().split())) m = 0 ans = 0 for i in range(n): if i > 0: ans += max(0, m - a[i]) m = max(a[i], m) print(ans)
p02578
s938595496
Accepted
N = int(input()) A = list(map(int, input().split())) B = [0]*N for i in range(N-1): if A[i] > A[i+1]: B[i+1] = A[i] - A[i+1] A[i+1] = A[i] ans = sum(B) print(ans)
p02578
s498583323
Accepted
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N-1): delta = A[i+1]-A[i] if delta < 0: A[i+1] += -delta ans += -delta print(ans)
p02578
s572329699
Accepted
n = int(input()) a = list(map(int,input().split())) mini = a[0] ans = 0 for i in range(n): if a[i]>mini: mini = a[i] else: ans += mini-a[i] print(ans)
p02578
s285064752
Accepted
n = int(input()) arr = list(map(int,input().split())) cur_max = arr[0] ans = 0 for i in range(1,n): if arr[i] <= cur_max: ans += abs(arr[i]-cur_max) else: cur_max = arr[i] print(ans)
p02578
s470323353
Accepted
# [] = list(map(int, input().split())) n = int(input()) aList = list(map(int, input().split())) hList = aList.copy() header = aList[0] for index, item in enumerate(aList[1:]): if header > item: hList[index+1] = header else: header = item dif = 0 for i in range(n): dif += hList[i] - aList[i] print(dif)
p02578
s597863018
Accepted
N=int(input()) A = list(map(int,input().split())) TOT = 0 MAX = 0 for i in range(N): if MAX < A[i]: MAX = A[i] else: TOT += MAX - A[i] print(TOT)
p02578
s827216161
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]: continue else: cnt = A[i-1] - A[i] ans += cnt A[i] += cnt print(ans) if __name__ == "__main__": main()
p02578
s243853563
Accepted
N = int(input()) A = list(map(int, input().split())) min_h, sum_h = 0, 0 for a in A: if min_h < a: min_h = a sum_h += min_h - a print(sum_h)
p02578
s768771264
Accepted
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 mi > a[i+1] or a[i] > a[i+1]: mi = max(a[i], mi) cost += mi - a[i+1] print(cost) return 0 if __name__ == "__main__": solve()
p02578
s505590765
Accepted
#!/usr/local/bin/python3 N = int(input()) A = list(map(int, input().split())) m = ans = 0 for i in range(N): m = max(m, A[i]) ans += m - A[i] print(ans)
p02578
s747084661
Accepted
n = int(input()) a = [int(x) for x in input().split()] c = 0 for i in range(n-1): if a[i] > a[i+1]: c += a[i] - a[i+1] a[i+1] = a[i] print(c)
p02578
s928806251
Accepted
N = int(input()) A = list(map(int,input().split())) cnt = 0 for i in range(N-1): if A[i] > A[i+1]: cnt += A[i]-A[i+1] A[i+1] += A[i]-A[i+1] print(cnt)
p02578
s344286939
Accepted
n=int(input()) A=[int(_) for _ in input().split()] c=A[0] ans=0 for a in A: if a<c: ans+=c-a else: c=a print(ans)
p02578
s296463505
Accepted
N=int(input()) A = list(map(int, input().split())) s = 0 x = 0 for i in A: if i < x: s += x - i else: x = i print(s)
p02578
s100287334
Accepted
def main(): n = int(input()) x = tuple([int(t)for t in input().split()]) m = x[0] ans = 0 for i in range(1,n): if m>x[i]: ans += m-x[i] else: m = x[i] print(ans) if __name__ == "__main__": main()
p02578
s877510941
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1, n): if a[i - 1] > a[i]: step = abs(a[i] - a[i - 1]) ans += step a[i] = a[i - 1] print(ans)
p02578
s385979521
Accepted
N = int(input()) A = list(map(int, input().split())) S = 0 h = A[0] for i in range(1, len(A)): if A[i] < h: S += (h - A[i]) h = max(h, A[i-1]) else: h = A[i] print(S)
p02578
s641629193
Accepted
n = int(input()) lst = list(map(int,input().split())) mx = lst[0] if n == 1: print(0) else: s =0 for i in range(1,n): if lst[i] < mx: s += mx -lst[i] if lst[i] > mx: mx = lst[i] print(s)
p02578
s193118747
Accepted
n,*a=map(int,open(0).read().split()) z=a[0] b=0 for q in a: if z>q: b+=(z-q) z=max(z,q) print(b)
p02578
s628854346
Accepted
N = int(input()) A = list(map(int,input().split())) maxnow = A[0] fumidaisum = 0 for i in range(1,N): if A[i]<maxnow: fumidaisum += -A[i]+maxnow elif A[i]>maxnow: maxnow = A[i] print(fumidaisum)
p02578
s591146964
Accepted
n = int(input()) a = list(map(int,input().split())) b = [0]*n for i in range(1,n): if a[i] < a[i-1]: b[i] = a[i-1] - a[i] a[i] = a[i-1] print(sum(b))
p02578
s767550980
Accepted
n=int(input()) A=list(map(int,input().split())) step=0 for i in range(n-1): if A[i+1]<A[i]: step+=A[i]-A[i+1] A[i+1]=A[i] print(step)
p02578
s297251278
Accepted
n = int(input()) a = list(map(int, input().split())) tmp = 0 sum = 0 for i in a: if tmp > i: dif = tmp - i sum += dif else: tmp = i print(sum)
p02578
s313319610
Accepted
n = int(input()) a = list(map(int, input().split(" "))) sum_step = 0 max_height = a[0] for i in range(1, n): if a[i] > max_height: max_height = a[i] if a[i] < max_height: sum_step += max_height - a[i] print(sum_step)
p02578
s109384744
Accepted
n = int(input()) a = list(map(int, input().split())) mae=a[0] sum=0 for i in range(len(a)-1): if a[i+1]<mae: sum=sum+(mae-a[i+1]) else: mae=a[i+1] print(sum)
p02578
s738380191
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: M=A[i] else: ans+=M-A[i] print(ans)
p02578
s125349419
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 x = a[0] for i in range(1, n): ans += max(x - a[i], 0) x = max(a[i], x) print(ans)
p02578
s297302193
Accepted
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)
p02578
s125807355
Accepted
#n, m, q = map(int, input().split()) #List = list(map(int, input().split())) #req = [list(map(int, input().split())) for _ in range(q)] #t = t[:-1] #print(ans[j], end = "") 改行無しで出力 #[0]*n #sort = sorted(a)[::-1] 降順 #if l[i] == l[j]: continue n = int(input()) a = list(map(int, input().split())) ans = 0 num = a[0] for i in range(n-1): if num < a[i+1]: num = a[i+1] else: ans += num - a[i+1] print(ans)
p02578
s463933037
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 high = a[0] for i in range(1, n): if a[i] < high: ans += high - a[i] else: high = a[i] print(ans)
p02578
s504598198
Accepted
def main(): n = int(input()) A = list(map(int, input().split())) s = 0 ans = 0 for a in A: if a > s: s = a else: ans += s - a print(ans) if __name__ == '__main__': main()
p02578
s066878874
Accepted
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_tmp > a_list[i]: sum += a_tmp - a_list[i] else: a_tmp = a_list[i] print(sum)
p02578
s089730641
Accepted
n=int(input()) a=list(map(int,input().split())) maxi=a[0] ans=0 for i in range(n): if a[i]<maxi: ans+=maxi-a[i] else: maxi=a[i] print(ans)
p02578
s235511934
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1, N): if A[i] > A[i-1]: continue else: ans += A[i-1] - A[i] A[i] = A[i-1] print(ans)
p02578
s286838989
Accepted
n = int(input()) #a, b = map(int,input().split()) a = list(map(int,input().split())) #l = [list(map(int,input().split())) for i in range(n)] ans=0 for i in range(1,n): if a[i-1]<=a[i]: pass else: dif=a[i-1]-a[i] ans+=dif a[i]=a[i]+dif print(ans)
p02578
s739825753
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)