fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;cin>>n;
  5. long long a[n];
  6. long long b[n];
  7. for(int i=0;i<n;i++){
  8. cin>>a[i];
  9. b[i]=a[i];
  10. }
  11. sort (b,b+n);
  12. int cnt=0;
  13. int x=0;
  14. int c[2];
  15. for(int i=0;i<n;i++){
  16. if (a[i]!=b[i]){
  17. cnt++;
  18. if (cnt<=2){
  19. c[x]=b[i];
  20. x++;
  21. }
  22. }
  23. }
  24. if (cnt==0){
  25. cout<<"yes"<<endl;
  26. cout<<a[0]<<" "<<a[0];
  27. }
  28. else if (cnt==2){
  29. cout<<"yes"<<endl;
  30. cout<<c[0]<<" "<<c[1];
  31. }
  32. else
  33. {
  34. cout<<"no";
  35. }
  36. }
Success #stdin #stdout 0s 988KB
stdin
Standard input is empty
stdout
no