fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n ; cin>>n;
  8. vector<int>arr(n);
  9. for(int i = 0 ; i<n ; i++){
  10. cin>>arr[i];
  11. }
  12. vector<int>pre(n),suf(n);
  13. int mini=INT_MAX; int maxi = INT_MIN;
  14. for(int i = 0 ; i < n ; i++){
  15. mini= min(mini,arr[i]);
  16. pre[i]=mini;
  17. }
  18. for(int i = n-1 ; i >=0 ; i--){
  19. maxi= max(mini,arr[i]);
  20. suf[i]=maxi;
  21. }
  22. bool ans = false ;
  23. for(int j = 1 ; j<n-1;j++){
  24. if(pre[j-1]<arr[j] && suf[j+1]>arr[j]) ans = true;
  25. }
  26. cout<<boolalpha;
  27. cout<<ans;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5296KB
stdin
6
 5 4 3 2 1 8 
stdout
false