fork download
  1. // Sort The Array
  2. #include<iostream>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. long long arr[100005];
  7.  
  8. int main() {
  9.  
  10. int start = 0, end = 0;
  11. int n;
  12. cin >> n;
  13.  
  14. for (int i = 0;i < n;i++) {
  15. cin >> arr[i];
  16. }
  17. int i;
  18. for (i = 0;i < n-1;i++) {
  19. if (arr[i] > arr[i + 1]) { start = i; break; }
  20. }
  21. int j;
  22. for (j = n - 1;j >= 1;j--) {
  23. if (arr[j] < arr[j - 1]) { end = j; break; }
  24. }
  25.  
  26. int index = (start + end) / 2;
  27.  
  28. for (int k = start;k < index;k++) {
  29. swap(arr[k], arr[n - k - 1]);
  30. }
  31.  
  32.  
  33. bool sorted = true;
  34. for (int i = 0; i < n; i++) {
  35. if (arr[i] > arr[i + 1]) {
  36. sorted = false;
  37. break;
  38. }
  39. }
  40. if (sorted) {
  41. cout << "yes" << endl;
  42. if (arr[start] > arr[end]) {
  43. cout << arr[end] << " " << arr[start] << endl;
  44. }
  45. else {
  46. cout << arr[start] << " " << arr[end] << endl;
  47. }
  48. }
  49. else {
  50. cout << "no" << endl;
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
yes
0 0