Skip to content

Instantly share code, notes, and snippets.

@markroxor
Created September 19, 2015 18:54
Show Gist options
  • Save markroxor/ac34b0e3be785ff44ed7 to your computer and use it in GitHub Desktop.
Save markroxor/ac34b0e3be785ff44ed7 to your computer and use it in GitHub Desktop.
Stock Maximize HackerRank DP Practice
from sys import stdin
nex = iter(map(int,stdin.read().split())).next
t = nex()
for _ in xrange(t):
n = nex()
list = []
for i in xrange(n):
list.append(nex())
maxi = 0
sum = 0
for i in xrange(n-1,-1,-1):
maxi = max(maxi,list[i])
sum += maxi - list[i]
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment