-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path451B.cpp
More file actions
89 lines (82 loc) · 1.14 KB
/
Copy path451B.cpp
File metadata and controls
89 lines (82 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Author: Akansha(akansha_2202)
* Date : 22/10/2019
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
int b[n];
int c[n];
for(int i=0;i<n;i++){
cin>>a[i];
c[i]=a[i];
}
for(int j=0;j<n;j++){
b[j]=0;
}
for(int i=0;i<n;i++){
if(i==0){
if(a[i]>a[i+1]){
b[i]=1;
continue;
}
}
else if(i==n-1){
if(a[i]<a[i-1]){
b[i]=1;
continue;
}
}
else if(a[i-1]>a[i]&&a[i]<a[i+1]){
b[i]=1;
continue;
}
else if(a[i-1]<a[i]&&a[i]>a[i+1]){
b[i]=1;
continue;
}
}
int x=1,y=1;
if(is_sorted(a,a+n)){
cout<<"yes"<<endl;
cout<<x<<" "<<y<<endl;
}
else{
int temp[n];
int k=0;
for(int i=0;i<n;i++){
if(b[i]==1){
temp[k]=i;
k++;
}
}
x=temp[0];
y=temp[1];
int m=x;
int l=y;
//swap(a[x],a[y]);
for(int i=x;i<=y;i++){
a[i]=c[l];
l--;
}
//for(int i=0;i<n;i++)
//cout<<a[i]<<" ";
if(is_sorted(a,a+n)){
cout<<"yes";
cout<<endl;
cout<<x+1<<" "<<y+1<<endl;
}
else
cout<<"no"<<endl;
//cout<<endl;
//cout<<temp[0]+1<<" "<<temp[1]+1<<endl;
}
/*for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}*/
return 0;
}