Advertisement
kostes

Untitled

Dec 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define all(c) c.begin(),c.end()
  4. using namespace std;
  5. typedef long long ll;
  6. const ll INF64 = 1e18 + 1337;
  7. const int INF32 = 1e9 + 228;
  8. const int MOD = 1e9 + 7;
  9. int n;
  10. ll a[50000];
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. #ifndef __WIN32
  15. ifstream cin("input.txt");
  16. ofstream cout("output.txt");
  17. #endif
  18. cin.tie(0);cout.tie(0);
  19.  
  20.  
  21. cin >> n;
  22. for(int i = 0; i < n; i++)
  23. cin >> a[i];
  24. ll ans = 0;
  25. for(int i = 0; i < n - 1; i++)
  26. {
  27. if(a[i] >= a[i + 1])
  28. {
  29. int ind = i;
  30. while( i < n - 1 && a[i] >= a[i + 1] ) i++;
  31. ans += a[ind] - a[i];
  32. }
  33. }
  34. bool ok = 1;
  35. for(int i = 0; i < n - 1; i++) if(a[i] >= a[i + 1]) ok = 0;
  36. if(ok)
  37. {
  38. ll maxi = a[0] - a[1];
  39. for(int i = 0; i < n - 1; maxi = max(maxi, a[i] - a[i+1]), i++);
  40. cout << maxi;
  41. return 0;
  42. }
  43. cout << ans;
  44.  
  45.  
  46.  
  47. #ifndef __WIN32
  48. cin.close();
  49. cout.close();
  50. #endif
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement