-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1101_Quick_Sort.cpp
45 lines (42 loc) · 985 Bytes
/
1101_Quick_Sort.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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> minn(n), maxx(n), v(n, 0);
int tempMax = -1;
for (int i = 0; i < n; ++i) {
cin >> v[i];
if (v[i] > tempMax) {
maxx[i] = tempMax;
tempMax = v[i];
} else {
maxx[i] = tempMax;
}
}
int tempMin = INT_MAX;
for (int i = n - 1; i >= 0; --i) {
if (v[i] < tempMin) {
minn[i] = tempMin;
tempMin = v[i];
} else {
minn[i] = tempMin;
}
}
vector<int> ans;
for (int i = 0; i < n; ++i) {
if (v[i] > maxx[i] && v[i] < minn[i]) ans.push_back(v[i]);
}
sort(ans.begin(), ans.end());
bool isFirst = true;
cout << ans.size() << endl;
for (int i : ans)
if (isFirst) {
cout << i;
isFirst = false;
} else {
cout << " " << i;
}
cout << endl;
return 0;
}