fork download
  1. #include <bits/stdc++.h>
  2. #include <string.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. int main() {
  7. ll t,a,temp,ans=0;
  8. cin>>t;
  9. cin>>temp;
  10. ll e=0;
  11. while(--t){
  12. cin>>a;
  13. ans+=max(temp-a,e);
  14. temp=max(temp,a);
  15. }
  16. cout<<ans;
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5288KB
stdin
10
1000000000 1 1 1 1 1 1 1 1 1
stdout
8999999991