forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Sort_the_Array.cpp
52 lines (51 loc) · 1.19 KB
/
B_Sort_the_Array.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v1(n);
for (int i = 0; i < n; i++)
cin >> v1[i];
vector<int> v2(v1);
sort(v2.begin(), v2.end());
int stidx(-1), endidx(-1);
for (int i = 0; i < n; i++)
if (v1[i] != v2[i])
{
stidx = i;
break;
}
for (int i = n - 1; i >= 0; i--)
if (v1[i] != v2[i])
{
endidx = i;
break;
}
if (stidx == -1 && endidx == -1)
cout << "yes\n1 1";
else
{
bool ans = true;
for (int i = stidx; i <= endidx; i++)
{
if (v1[i] != v2[endidx - i + stidx])
{
// cout << stidx << " " << endidx << endl;
// cout << i << " " << endidx - i + stidx << endl;
// cout << "false: i:" << i << " vals: " << v1[i] << " " << v2[endidx - i + stidx] << endl;
ans = false;
break;
}
}
if (ans)
{
cout << "yes" << endl
<< stidx + 1 << " " << endidx + 1;
}
else
{
cout << "no";
}
}
}