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. for (int k = start;k < end;k++) {
  27. swap(arr[k], arr[n - k - 1]);
  28. }
  29.  
  30.  
  31. bool sorted = true;
  32. for (int i = 0; i < n; i++) {
  33. if (arr[i] > arr[i + 1]) {
  34. sorted = false;
  35. break;
  36. }
  37. }
  38. if (sorted) {
  39. cout << "yes" << endl;
  40. if (arr[start] > arr[end]) {
  41. cout << arr[end] << " " << arr[start] << endl;
  42. }
  43. else {
  44. cout << arr[start] << " " << arr[end] << endl;
  45. }
  46. }
  47. else {
  48. cout << "no" << endl;
  49. }
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
yes
0 0