fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5.  
  6. bool isSortedAscending(const vector<int>& vec) {
  7. return is_sorted(vec.begin(), vec.end());
  8. }
  9.  
  10. int main()
  11. {
  12. FIO
  13.  
  14. // Moneer's coding space
  15.  
  16. int n;
  17. vector<int>arr(n);
  18. int start = -1;
  19. int end = -1;
  20.  
  21. for (size_t i = 0; i < n; i++) cin >> arr[i];
  22.  
  23. // selecting the start of the out of order segment
  24. for(int i = 0;i < n - 1;i++){
  25. if(arr[i] > arr[i + 1]) {
  26. start = i;
  27. break;
  28. }
  29. }
  30.  
  31. if (start == -1) {
  32. cout << "yes\n1 1\n";
  33. return 0;
  34. }
  35.  
  36. // selecting the end
  37. for (int i = n - 1; i > 0; i--)
  38. {
  39. if(arr[i] < arr[i - 1]) {
  40. end = i;
  41. break;
  42. }
  43. }
  44.  
  45. reverse(arr.begin() + start, arr.begin() + end + 1);
  46.  
  47. if (isSortedAscending(arr)){
  48. cout << "yes" << endl;
  49. cout << start + 1 << " " << end + 1 << endl;
  50. }
  51. else cout << "no" << endl;
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
yes
1 1