#include <iostream>
#include <vector>
int main() {
int T;
std::cin >> T;
int N;
while(T--) {
std::cin >> N;
std::vector<int> nums(N, 0);
for(int i = 0; i < N; ++i) {
std::cin >> nums[i];
}
long long result = 0; // !
int max = nums[N - 1];
for(int i = N - 2; i >= 0; --i) {
if(max > nums[i]) {
result += (max - nums[i]);
} else {
max = nums[i];
}
}
std::cout << result << std::endl;
}
return 0;
}
HackerRank - Stock Maximize
最新推荐文章于 2017-12-07 19:49:03 发布