-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivot.cpp
40 lines (34 loc) · 849 Bytes
/
pivot.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
#include <iostream>
#include <vector>
using namespace std;
int main () {
int elements;
int count = 0;
long min, max;
cin >> elements;
long input[elements], rightMin[elements], leftMax[elements];
for (int i = 0; i < elements; i++) {
cin >> input[i];
}
max = input[0];
for (int i = 0; i < elements; i++) {
if (!i) leftMax[i] = input[i];
else {
if (input[i-1] > max) max = input[i-1];
leftMax[i] = max;
}
}
min = input[elements-1];
for (int i = elements-1; i >= 0; i--) {
if (i == elements-1) rightMin[i] = input[i];
else {
if (input[i+1] < min) min = input[i+1];
rightMin[i] = min;
}
}
for (int i = 0; i < elements; i++) {
if ((input[i] >= leftMax[i] && input[i] < rightMin[i]) || (i == elements-1 && input[i] <= rightMin[i] && input[i] >= leftMax[i])) count++;
}
cout << count << endl;
return 0;
}