-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·57 lines (46 loc) · 1.04 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·57 lines (46 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> V(n, 0);
for (int i = 0; i < n; ++i)
cin >> V[i];
vector<int> left_max(n, 0);
for (int i = 0; i < n; ++i)
{
if (i == 0)
left_max[i] = V[i];
else
left_max[i] = max(left_max[i - 1], V[i]);
}
vector<int> right_min(n, 0);
for (int i = n - 1; i >= 0; --i)
{
if (i == n - 1)
right_min[i] = V[i];
else
right_min[i] = min(right_min[i + 1], V[i]);
}
int pivots = 0;
for (int i = 0; i < n; ++i)
{
bool left_OK = false;
bool right_OK = false;
if (i == 0)
left_OK = true;
else if (left_max[i - 1] <= V[i])
left_OK = true;
if (i == n - 1)
right_OK = true;
else if (right_min[i + 1] > V[i])
right_OK = true;
if (left_OK && right_OK)
{
++pivots;
}
}
cout << pivots << endl;
return 0;
}