fork download
  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n,y,z;
  8. cin>>n;
  9. int arr[n],sor[n];
  10. int check=0,x[n];
  11. int k=0;
  12. while(cin>> arr[k])
  13. {sor[k]=arr[k]; k++; }
  14.  
  15.  
  16. if(n>2)
  17. sort(sor,sor+n);
  18. else if(n==2)
  19. {
  20. if(sor[0]>sor[1])
  21. {
  22. int temp= sor[0];
  23. sor[0]=sor[1];
  24. sor[1]=temp;
  25. }
  26. }
  27. int j=0;
  28. for(int i=0;i<n;i++)
  29. {
  30.  
  31. if(sor[i]!=arr[i])
  32. {check++; z=i;}
  33.  
  34.  
  35. if(check==1&&arr[i]!=sor[i])
  36. y=i;
  37. }
  38.  
  39.  
  40.  
  41. if(check==0)
  42. {cout<<"yes"<<endl; cout<<arr[0]<<" "<< arr[0];}
  43.  
  44. else
  45. { check=0;
  46. for(int i=y;i<=z;i++)
  47. {if(sor[z+y-i]==arr[i])
  48. check++;
  49. }
  50. if(check==z-y+1)
  51. {cout<<"yes"<<endl; cout<<sor[y]<<" "<< sor[z];}
  52. else cout<<"no";
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 4584KB
stdin
2
58 4
stdout
yes
4 58