fork download
  1. #include <iostream>
  2. using namespace std;
  3. bool avail(int n,int arr[]){
  4. int s[n];
  5. s[n-1]=arr[n-1];
  6. int p=arr[0];
  7. for(int i=n-2;i>=0;i--){
  8. s[i]=max(s[i+1],arr[i]);
  9. }
  10. for(int i=1;i<=n-2;i++){
  11. if(arr[i]>p && arr[i]<s[i+1]){
  12. return true;
  13. }
  14. p=min(p,arr[i]);
  15. }
  16. return false;
  17. }
  18.  
  19. int main() {
  20. // your code goes here
  21. int n;
  22. cin>>n;
  23. int arr[n];
  24. for(int i=0;i<n;i++){
  25. cin>>arr[i];
  26. }
  27. if(avail(n,arr)){
  28. cout<<"There exits triplets";
  29. }
  30. else{
  31. cout<<"There does exits triplets";
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 5316KB
stdin
8
18 5 4 3 2 1 8 10
stdout
There exits triplets