Advertisement
facug91

Untitled

Apr 14th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. /*
  2.         By: facug91
  3.         From:
  4.         Name:
  5.         Date: 14/04/2016
  6. */
  7.  
  8. #include <bits/stdc++.h>
  9. #define endl "\n"
  10. #define EPS 1e-9
  11. #define MP make_pair
  12. #define F first
  13. #define S second
  14. #define DB(x) cerr << " #" << (#x) << ": " << (x)
  15. #define DBL(x) cerr << " #" << (#x) << ": " << (x) << endl
  16. const double PI = acos(-1.0);
  17.  
  18. #define INF 1000000000
  19. //#define MOD 1000000007ll
  20. #define MAXN 100000005
  21.  
  22. using namespace std;
  23. typedef long long ll;
  24. typedef unsigned long long llu;
  25. typedef pair<int, int> ii; typedef pair<ii, ii> iiii;
  26. typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iiii> viiii;
  27.  
  28. ll n, a[1000005], ans, mx;
  29.  
  30. int main () {
  31.     #ifdef ONLINE_JUDGE
  32.         ios_base::sync_with_stdio(0); cin.tie(0);
  33.     #endif
  34.     //cout<<fixed<<setprecision(3); //cerr<<fixed<<setprecision(3); //cin.ignore(INT_MAX, ' '); //cout << setfill('0') << setw(5)
  35.     int tc = 1, i, j;
  36.    
  37.     cin>>tc;
  38.     while (tc--) {
  39.         cin>>n;
  40.         for (i=0; i<n; i++) cin>>a[i];
  41.         mx = -1; ans = 0;
  42.         for (i=n-1; i>=0; i--) {
  43.             if (a[i] > mx) mx = a[i];
  44.             else ans += mx - a[i];
  45.         }
  46.         cout<<ans<<endl;
  47.     }
  48.    
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement