Created
September 19, 2015 18:54
-
-
Save markroxor/ac34b0e3be785ff44ed7 to your computer and use it in GitHub Desktop.
Stock Maximize HackerRank DP Practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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