problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p02578
s874408802
Accepted
N = int(input()) A = list(map(int, input().split())) sum_min = 0 before_height = A[0] for a in A[1:]: if before_height <= a: before_height = a else: sum_min += before_height - a print(sum_min)
p02578
s881003139
Accepted
n = int(input()) la = [int(w) for w in input().split()] ans = 0 h = la[0] for a in la[1:]: if a <= h: ans += h-a else: h = a print(ans)
p02578
s009707115
Accepted
N = int(input()) a = list(map(int,input().split())) step = 0 M = a[0] for i in range(1,N): if a[i] <= M: step += M-a[i] else: M = a[i] print(step)
p02578
s972299597
Accepted
N = int(input()) arr = list(map(int, input().split())) length = 0 for i in range(N-1): if arr[i+1] < arr[i]: length += arr[i] - arr[i+1] arr[i+1] += arr[i] - arr[i+1] print(length)
p02578
s096608994
Accepted
N = int(input()) h = list(map(int, input().split())) s = 0 for i in range(N-1): d = h[i] - h[i+1] if d > 0: s += d h[i+1] = h[i] print(s)
p02578
s149609741
Accepted
# -*- coding: utf-8 -*- """ Created on Sat Aug 15 17:00:46 2020 @author: saito """ # %% import phase # %% define phase # %% input phase n = int(input()) a = list(map(int, input().split())) # %% process phase ans = 0 f = 0 for ai in a: if f <= ai: f = ai else: ans += f - ai # %%output phas...
p02578
s502296003
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
s116091863
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1, N): if A[i] < A[i-1]: step = A[i-1] - A[i] A[i] += step ans += step print(ans)
p02578
s016854280
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N-1): if A[i] > A[i+1]: diff = A[i] - A[i+1] ans += diff A[i+1] += diff print(ans)
p02578
s127934704
Accepted
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): N=ii() A=list(mi()) mx = 0 ans = 0 for i in range(N): if mx > ...
p02578
s164179426
Accepted
n = int(input()) a = list(map(int, input().split())) temp, ans = a[0], 0 for i in range(1, n): if a[i] < temp: ans += temp - a[i] else: temp = a[i] print(ans)
p02578
s986790795
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 max_a = 0 for ai in A: max_a = max(ai, max_a) ans += (max_a-ai) print(ans)
p02578
s668507385
Accepted
N = int(input()) A = [int(s) for s in input().split()] ans = 0 for i in range(1, N): if A[i - 1] >= A[i]: difference = A[i - 1] - A[i] A[i] += difference ans += difference print(ans)
p02578
s535603037
Accepted
N = int(input()) List = list(map(int,input().split())) counter = 0 height = List[0] for i in range(1,N): if List[i] < height: counter += height - List[i] else: height = List[i] print(counter)
p02578
s218194314
Accepted
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n=int(input()) a=lnii() ans=0 for i in range(1,n): if a[i-1]>a[i]: sa=a[i-1]-a[i] ans+=sa num=a[i]+sa a[i]=num print(ans)
p02578
s500174342
Accepted
def main(): n = int(input()) x = list(map(int, input().split())) ans = 0 for i in range(n-1): if x[i] > x[i+1]: ans += x[i]-x[i+1] x[i+1] = x[i] print(ans) main()
p02578
s755986414
Accepted
n = input() heights = map(int, input().split()) max_height = 0 step_sum = 0 for i in heights: if max_height < i: max_height = i if max_height > i: step_sum += max_height - i print(step_sum)
p02578
s972815374
Accepted
N = int(input()) A = [int(x) for x in 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
s725983107
Accepted
n = int(input()) A = list(map(int, input().split())) ans = 0 max = A[0] for i in range(1, n): if A[i] > max: max = A[i] else: ans += max - A[i] print(ans)
p02578
s084384134
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 max_a = a[0] for i in range(1,n): if max_a > a[i]: ans += max_a - a[i] else: max_a = a[i] print(ans)
p02578
s604219642
Accepted
_ = input() A = [int(i) for i in input().split()] ans = 0 for i in range(len(A) - 1): h = max(A[i] - A[i + 1], 0) if h != 0: A[i + 1] += h ans += h print(ans)
p02578
s482706961
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1, n): temp = max(a[i - 1] - a[i], 0) a[i] += temp ans += temp print(ans)
p02578
s291040142
Accepted
x = int(input()) lst = list(map(int, input().split())) i = 1 cnt = 0 a = lst[0] if x == 1: print(0) else: while True: b = lst[i] if b < a: cnt += abs(b - a) a = a else: a = b if i >= x - 1: break i += 1 print(cnt)
p02578
s322147709
Accepted
def main(): N=input() arr=list(map(int,input().split())) sum=0 for i in range(1,int(N)): if arr[i] < arr[i-1]: sum+= (arr[i-1]-arr[i]) arr[i]=arr[i-1] print(sum) if __name__ == '__main__': main()
p02578
s349069633
Accepted
n = int(input()) A = list(map(int, input().split())) top = A[0] score = 0 for a in A[1:]: if a <= top: score += (top - a) else: top = a print(score)
p02578
s085072775
Accepted
#!/usr/bin/python3 """ https://atcoder.jp/contests/abc176/tasks/abc176_c Step """ def solve(a, n): 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] return ans if __name__ == "__main__": n = int(input()) a = [(lambda x: int(x))(x...
p02578
s023257613
Accepted
import math n = int(input()) alist = list(map(int,input().split())) maxmin = -math.inf board = 0 for i in range(n): a = alist[i] if a > maxmin: maxmin = a else: board += maxmin - a print(board)
p02578
s841289826
Accepted
n = int(input()) alist = list(map(int, input().split())) temp = alist[0] count = 0 for a in alist[1:]: if a < temp: count += temp - a elif a > temp: temp = a print(count)
p02578
s380764045
Accepted
import sys def input(): return sys.stdin.readline().rstrip() def main(): n = int(input()) A = list(map(int,input().split())) high = 0 ans = 0 for a in A: if high > a: ans += high - a elif high < a: high = a print(ans) if __name__=='__main__': main()
p02578
s199138722
Accepted
n=int(input()) a=list(map(int,input().split())) count=0 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
s415943538
Accepted
N=int(input()) A=list(map(int,input().split())) b=A[0] c=0 d=len(A) for i in range(1,d): if b>A[i]: c+=b-A[i] else: b=A[i] print(c)
p02578
s208150592
Accepted
N=int(input()) A=list(map(int,input().split())) a=0 b=A[0] for i in range(1,N): if b<=A[i]: b=A[i] elif b>A[i]: a+=(b-A[i]) A[i]=b b=A[i] print(a)
p02578
s552842254
Accepted
l = int(input()) xs = [int(x) for x in input().split()] step = 0 max = 0 for x in xs: # This x must be the max in the preceeding numbers if x > max: max = x continue # Current max, so no step is needed step += max - x print(step)
p02578
s792150396
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(1, N): t = A[i - 1] - A[i] if t > 0: ans += t A[i] += t print(ans)
p02578
s017678312
Accepted
n = int(input()) a = list(map(int,input().split())) ans = 0 prev_max=a[0] for i in a: if prev_max > i: ans+= prev_max-i elif prev_max < i: prev_max = i print(ans)
p02578
s863443986
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
s296199198
Accepted
N = int(input()) A = list(map(int,input().split())) sum = 0 for i in range(len(A)-1): if A[i+1] < A[i]: sum += A[i] - A[i+1] A[i+1] = A[i] else: pass print(sum)
p02578
s925726063
Accepted
def main(): n = int(input()) A = list(map(int,input().split())) front = 0 ans = 0 for a in A: if front < a: front = a else: ans += front - a print(ans) return if __name__ == '__main__': main()
p02578
s092973970
Accepted
x=int(input()) l=list(map(int,input().split(" "))) sum=0 mx=-1000 for i in range(len(l)-1): mx=max(mx,l[i]) if l[i+1]<mx: sum+=mx-l[i+1] print(sum)
p02578
s718435317
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 curMax = A[0] for a in A: if curMax >= a: ans += (curMax - a) else: curMax = a print(ans)
p02578
s746502673
Accepted
N = int(input()) ARR = list(map(int, input().split())) sum_of_Humidai = 0 for i in range(1, len(ARR)): diff = (ARR[i - 1] - ARR[i]) if diff > 0: ARR[i] += diff sum_of_Humidai += diff else: print(sum_of_Humidai)
p02578
s397909850
Accepted
N = int(input()) A = list(map(int, input().split())) count = 0 now = A[0] for i in range(N): if now > A[i]: count += now - A[i] else: now = A[i] print(count)
p02578
s345525866
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+=abs(a[i]-a[i-1]) a[i] = a[i-1] print(ans)
p02578
s778848325
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 for n in range(N-1): t = A[n] - A[n+1] if t <= 0: continue else: A[n+1] += t ans += t print(ans)
p02578
s810707969
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 B = [A[0]] for i in range(1, N): if A[i]<B[-1]: ans += B[-1]-A[i] B.append(B[-1]) else: B.append(A[i]) print(ans)
p02578
s688317512
Accepted
n = int(input()) a = list(map(int, input().split())) f_sum = 0 prev = a[0] for i in range(n-1): if prev > a[i+1]: f_sum += prev - a[i+1] else: prev = a[i+1] print(f_sum)
p02578
s211403240
Accepted
n=int(input()) *a,=map(int, input().split()) mx=0 ans=0 for i in range(n): if mx>a[i]: ans+=mx-a[i] else: mx=a[i] print(ans)
p02578
s442170861
Accepted
N = int(input()) A_list = input().split() A_list = [int(x) for x in A_list] sum = 0 tmp_mae = A_list[0] for i in range(1,N): tmp_ushiro = A_list[i] if(tmp_mae > tmp_ushiro): sabun = tmp_mae - tmp_ushiro sum += sabun else: sabun = 0 tmp_mae = tmp_ushiro + sabun print(sum)
p02578
s585172689
Accepted
n = int(input()) a = list(map(int, input().split())) sum = 0 mae = a[0] for ai in a[1:]: if mae > ai: sum = sum + mae - ai continue mae = ai print(sum)
p02578
s255121135
Accepted
N = int(input()) A = list(map(int, input().split())) iter_A = iter(A) ans = 0 for i in range(1, len(A)): if A[i-1] > A[i]: ans += A[i-1] - A[i] A[i] = A[i-1] print(ans)
p02578
s930637389
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] else: pass print(cnt)
p02578
s086617704
Accepted
n=int(input()) a = list(map(int,input().split())) b = a[0] total=0 for i in a: if i<b: total+=b-i else: b=i print(total)
p02578
s609166911
Accepted
from sys import stdin readline = stdin.readline n = int(readline()) a = list(map(int, readline().split())) x = 0 ans = 0 for i in a: if x > i: ans += (x-i) else: x = i print(ans)
p02578
s988380637
Accepted
from math import gcd from math import factorial as f from math import ceil, floor, sqrt import math import bisect import re import heapq from copy import deepcopy import itertools from itertools import permutations from sys import exit ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: ...
p02578
s558869026
Accepted
N = int(input()) A = list(map(int, input().split())) maxF = A[0] ans = 0 for i in range(1,N): if maxF > A[i]: ans += (maxF - A[i]) maxF = max(A[i], maxF) print(ans)
p02578
s963803130
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 tgt = A[0] for i in range(1, N): if tgt < A[i]: tgt = A[i] elif tgt > A[i]: ans += tgt - A[i] print(ans)
p02578
s333056611
Accepted
n=int(input()) a=list(map(int,input().split())) ans=0 p=0 for i in range(n): if a[i]<p: ans+=p-a[i] else: p=a[i] print(ans)
p02578
s779951355
Accepted
N = int(input()) A = list(map(int, input().split())) S = 0 H = A[0] for i in range(1, N): if (A[i] < H): S = S + (H-A[i]) else: H = A[i] print(S)
p02578
s508051610
Accepted
def resolve(): n = int(input()) a = list(map(int, input().split())) ans = [0] * n for i in range(n-1): if a[i] <= a[i + 1]: continue else: ans[i+1] = a[i] - a[i+1] a[i+1] = a[i] ans = sum(ans) print(ans) resolve()
p02578
s018576291
Accepted
n=int(input()) l=list(map(int,input().split())) def solve(n,l): if n==1: return 0 ans=0 m=0 for i in range(n): if l[i]>=m: m=l[i] else: ans+=max(0,m-l[i]) return ans print(solve(n,l))
p02578
s698258963
Accepted
n = int(input()) a = list(map(int,input().split())) current = a[0] steps = 0 for i in range(n): if a[i] < current: steps += current-a[i] else: current = a[i] print(steps)
p02578
s487727830
Accepted
n = int(input()) lis = list(map(int, input().split())) sum = 0 m = lis[0] for i in lis: if m > i: sum += (m-i) else: m = i print(sum)
p02578
s343743498
Accepted
N=int(input()) A=list(map(int,input().split())) nowmax=A[0] ans=0 for i in range(1,N): if A[i]>nowmax: nowmax=A[i] ans+=nowmax-A[i] print(ans)
p02578
s371144459
Accepted
N = int(input()) A = list(map(int, input().split())) sum=0 sa=0 for i in range(N-1): if A[i] <= A[i+1]: continue else: sa = A[i]-A[i+1] A[i+1]=A[i] sum += sa print(sum)
p02578
s429459746
Accepted
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: ans+=a[i-1]-a[i] a[i]=a[i-1] print(ans)
p02578
s723818194
Accepted
N = int(input()) A = list(map(int, input().split())) ans = 0 max = 0 for i in range(N): if max < A[i]: max = A[i] else: ans += max - A[i] print(ans)
p02578
s678017168
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1, n): if a[i - 1] > a[i]: diff = a[i - 1] - a[i] ans += diff a[i] += diff print(ans)
p02578
s230798495
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
s246004546
Accepted
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input n = int(input()) a = list(map(int, input().split())) #output answer = 0 for i in range(1, n): if a[i] < a[i-1]: answer += a[i-1]-a[i] a[i] = a...
p02578
s457135264
Accepted
n = int(input()) A = list(map(int,input().split())) cnt=0 for i in range(n-1): if A[i+1] < A[i]: s = A[i]-A[i+1] A[i+1] += s cnt += s print(cnt)
p02578
s952225987
Accepted
N = int(input()) dai = 0 A = list(input().split()) max = int(A[0]) for i in range(1, len(A)): if int(A[i]) < int(A[i-1]): dai += int(A[i-1]) - int(A[i]) A[i] = A[i-1] print(dai)
p02578
s462473641
Accepted
n = input() aa = list(map(int, input().split())) max_a = aa[0] step = 0 for i in range(1, len(aa)): if max_a > aa[i]: # 踏み台必要 step += max_a - aa[i] else: max_a = aa[i] print(step)
p02578
s974899791
Accepted
if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) target = 0 ans = 0 for h in a: if target <= h: target = h else: ans += target - h print(ans)
p02578
s693950844
Accepted
N = int(input()) A = list(map(int,input().split())) max_h,ans = A[0],0 for i in range(1,N): if max_h > A[i]: ans += (max_h - A[i]) else: max_h = A[i] print(ans)
p02578
s261416953
Accepted
n = int(input()) a =[int(x) for x in input().split()] num = 0 min_num = a[0] for i in a[1:]: if i < min_num: num += min_num-i else: min_num = i print(num)
p02578
s272038879
Accepted
n = int(input()) a = list(map(int, input().split())) daisum = 0 minh = 0 for i in a: dai = 0 if i < minh: dai = minh - i daisum += dai elif i > minh: minh = i print(daisum)
p02578
s852278970
Accepted
N = int(input()) A = list(map(int,input().split())) cnt = 0 for i in range(len(A)): if i==0: continue if A[i-1]-A[i]>0: cnt +=A[i-1]-A[i] A[i]=A[i-1] print(cnt)
p02578
s220744647
Accepted
import numpy as np N=int(input()) A=list(map(int,input().split())) F=[] for i in np.arange(len(A)-1): if(A[i]>A[i+1]): F.append(A[i]-A[i+1]) A[i+1]=A[i] print(sum(F))
p02578
s593029731
Accepted
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A = np.array(read().split(), np.int64)[1:] B = np.maximum.accumulate(A) print(np.sum(B - A))
p02578
s240898742
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: step = a[i-1] - a[i] a[i] += step ans += step print(ans)
p02578
s946529302
Accepted
N = int(input()) A = list(map(int,input().split())) ans = 0 prev = A[0] for i in range(N): if prev > A[i]: ans += prev-A[i] else: prev = A[i] print(ans)
p02578
s824745408
Accepted
N = int(input()) A = list(map(int, input().split())) sum = 0 for i in range(N-1): if A[i] > A [i+1]: sum += A[i] - A[i+1] A[i+1] = A[i] print(sum)
p02578
s686779493
Accepted
import sys input = lambda : sys.stdin.readline().rstrip() n = int(input()) nums = map(int, input().split(" ")) out = 0 for i, num in enumerate(nums): if i == 0: cur_max = num else: if cur_max > num: out += cur_max - num else: cur_max = num print(out)
p02578
s158283950
Accepted
N=int(input()) A=list(map(int,input().split())) step=0 for i in range(N): if i == 0: pass else: if A[i]-A[i-1]>=0: pass else: step += (A[i-1]-A[i]) A[i] += (A[i-1]-A[i]) print(step)
p02578
s284826639
Accepted
N = int(input()) A = [int(x) for x in 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
s690365375
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
s265747968
Accepted
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1, len(a)): if a[i] <= a[i - 1]: ans += abs(a[i] - a[i - 1]) a[i] = a[i - 1] else: ans += 0 print(ans)
p02578
s541054805
Accepted
n = int(input()) a = list(map(int, input().split())) result = 0 tmp = a[0] for i in range(1, n): if tmp >= a[i]: result += tmp - a[i] else: tmp = a[i] print(result)
p02578
s688419105
Accepted
n = int(input()) height = list(map(int,input().split())) standard = height[0] ans = 0 for i in range(n): if height[i] > standard: standard = height[i] elif height[i] < standard: ans += standard - height[i] print(ans)
p02578
s795821076
Accepted
N = int(input()) A = input().split() A = [int(i) for i in A] total = 0 amax = A[0] for i in range(N-1): if A[i+1] < amax: total = total + (amax - A[i+1]) if A[i+1] > amax: amax = A[i+1] print(total)
p02578
s582332965
Accepted
N = int(input()) A = list(map(int, input().split(' '))) ans = 0 gap = 0 for i in range(1,N): if ( A[i-1] + gap ) > A[i]: gap = ( A[i-1] + gap ) - A[i] else: gap = 0 ans += gap print(ans)
p02578
s805529132
Accepted
n=int(input()) a=list(map(int,input().split())) an =0 ki=a[0] for i in range(n-1): wk=ki-a[i+1] if wk>0: an+=wk ki=max(ki,a[i+1]) print(an)
p02578
s890483064
Accepted
N = int(input()) high_list = list(map(int,input().split())) l = high_list[0] count = 0 for i in range(N-1): i_a = high_list[i] i_b = high_list[i+1] if(i_a > i_b): dai = i_a - i_b i_b = i_b + dai high_list[i+1] = i_b count += dai print(count)
p02578
s386821086
Accepted
N=int(input()) A=list(map(int,input().split())) count=0 last=A[0] for i in range(1,N): if A[i]<last: count+=last-A[i] else: last=A[i] print(count)
p02578
s914429314
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
s669840811
Accepted
N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(1,N): diff = A[i - 1] - A[i] if diff <= 0: pass else: ans += diff A[i] += diff print(ans)
p02578
s294833011
Accepted
N=int(input()) a=list(map(int,input().split())) ans=0 for i in range(1,N): if a[i]<a[i-1]: tmp=a[i-1]-a[i] a[i]+=tmp ans+=tmp print(ans)
p02578
s529887227
Accepted
#!/usr/bin/env python3 N = int(input()) A = list(map(int, input().split())) ret = 0 h = 0 for i in range(1, N): if A[i] < A[i-1]+h: ret += A[i-1] + h - A[i] h = A[i-1] + h - A[i] else: h = 0 print(ret)
p02578
s221664266
Accepted
n=int(input()) A=list(map(int,input().split())) now=0 ans=0 for a in A: if now>a: ans+=now-a else: now=a print(ans)
p02578
s453748938
Accepted
N = int(input()) A = list(map(int,input().split())) if N == 1: print(0) exit() 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)