Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- By: facug91
- From:
- Name:
- Date: 14/04/2016
- */
- #include <bits/stdc++.h>
- #define endl "\n"
- #define EPS 1e-9
- #define MP make_pair
- #define F first
- #define S second
- #define DB(x) cerr << " #" << (#x) << ": " << (x)
- #define DBL(x) cerr << " #" << (#x) << ": " << (x) << endl
- const double PI = acos(-1.0);
- #define INF 1000000000
- //#define MOD 1000000007ll
- #define MAXN 100000005
- using namespace std;
- typedef long long ll;
- typedef unsigned long long llu;
- typedef pair<int, int> ii; typedef pair<ii, ii> iiii;
- typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iiii> viiii;
- ll n, a[1000005], ans, mx;
- int main () {
- #ifdef ONLINE_JUDGE
- ios_base::sync_with_stdio(0); cin.tie(0);
- #endif
- //cout<<fixed<<setprecision(3); //cerr<<fixed<<setprecision(3); //cin.ignore(INT_MAX, ' '); //cout << setfill('0') << setw(5)
- int tc = 1, i, j;
- cin>>tc;
- while (tc--) {
- cin>>n;
- for (i=0; i<n; i++) cin>>a[i];
- mx = -1; ans = 0;
- for (i=n-1; i>=0; i--) {
- if (a[i] > mx) mx = a[i];
- else ans += mx - a[i];
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement