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