-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path451B-SorttheArray.cpp
More file actions
67 lines (60 loc) · 1.21 KB
/
451B-SorttheArray.cpp
File metadata and controls
67 lines (60 loc) · 1.21 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
// B. Sort the Array
// https://codeforces.com/problemset/problem/451/B
// Time 15 ms
// Memory 1800 KB
// Rating 1300
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
vector<int> a, b;
for (int i = 0; i < t; i++)
{
int temp;
cin >> temp;
a.push_back(temp);
b.push_back(temp);
}
sort(b.begin(), b.end());
// for (auto x : a)
// cout << x << " ";
// cout << endl;
// for (auto x : b)
// cout << x << " ";
if (a == b)
{
cout << "yes\n"
<< "1 1\n";
}
else
{
int l, r;
for (int i = 0; i < t - 1; i++)
{
if (a[i] > a[i + 1])
{
l = i;
break;
}
}
for (int i = t - 1; i > 0; i--)
{
if (a[i] < a[i - 1])
{
r = i;
break;
}
}
reverse(a.begin() + l, a.begin() + r + 1);
if (a == b)
cout << "yes\n"
<< l + 1 << " " << r + 1 << "\n";
else
cout << "no\n";
}
return 0;
}