fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11.  
  12. int main()
  13. {
  14. Faster;
  15. int n; cin >> n;
  16. int a[n];
  17. for(auto &x : a) cin >> x;
  18. int ans = INT_MIN, id1, id2;
  19. for(int i = 1; i < n; i++)
  20. {
  21. if(ans < a[i] - a[i-1])
  22. {
  23. ans = a[i] - a[i-1];
  24. id1 = i-1;
  25. id2 = i;
  26. }
  27. }
  28. for(int i = 2; i < n; i++)
  29. {
  30. if(ans < a[i] - a[i-2])
  31. {
  32. ans = a[i] - a[i-2];
  33. id1 = i - 2;
  34. id2 = i;
  35. }
  36. }
  37. cout << ans;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5272KB
stdin
5
1 2 2 3 4
stdout
2