Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main ()
  5. {
  6. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //tat dong bo giup chuong trinh chay nhanh hon
  7. int N;
  8. cin >> N;
  9. int a[N], b[N-1], c[N-1];
  10. for (int i=0; i<N; i++)
  11. {
  12. cin >> a[i];
  13. if (i>0 && i<N-1) b[i]=min(a[i], b[i-1]);
  14. else if (i==0) b[0]=a[0];
  15. }
  16. reverse (a, a+N);
  17. for (int i=0; i<N; i++)
  18. {
  19. if (i>0 && i<N-1) c[i]=max(a[i], c[i-1]);
  20. else if (i==0) c[0]=a[0];
  21. }
  22. reverse (c, c+N-1);
  23. int S=-1e9;
  24. for (int i=0; i<N-1; i++)
  25. {
  26. S=max(S,c[i]-b[i]);
  27. }
  28. cout << S;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement